/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Runtime Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 568.0 KiB
#3 Runtime Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 580.0 KiB

Code

#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

#define endl '\n'
#define ll long long
#define ull unsigned long long
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve() {
    ll n, m; cin >> n >> m;
    vector<ull> p(n);
    rep(i, 0, n) cin >> p[i];
    
    while (m-- && sz(p) > 1) {
        ull j = 0;
        string max_str = to_string(p[0]) + to_string(p[1]);
        ull max_num = stoull(max_str);

        rep(i, 0, sz(p) - 1) {
            string current_str = to_string(p[i]) + to_string(p[i + 1]);
            ull current_num = stoull(current_str);
            if (current_num > max_num) {
                max_num = current_num;
                j = i;
            }
        }

        p[j] = max_num;
        p.erase(p.begin() + j + 1);
    }
    
    ull result = *max_element(all(p));
    cout << result << endl;
}

int main() {
    fast;
    ll t; cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 18:02:30
Judged At
2024-11-11 03:10:51
Judged By
Score
5
Total Time
2ms
Peak Memory
580.0 KiB