/ SeriousOJ /

Record Detail

System Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 764.0 KiB
#2 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 6ms 436.0 KiB
#3 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#4 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#5 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#6 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#7 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#8 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#9 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 1ms 532.0 KiB
#10 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#11 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 1ms 532.0 KiB
#12 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.0 KiB
#13 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 3ms 532.0 KiB
#14 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 580.0 KiB
#15 System Error terminate called after throwing an instance of 'std::out_of_range' what(): stoull 2ms 532.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-08-16 18:02:30
Judged By
Score
5
Total Time
6ms
Peak Memory
764.0 KiB