/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Runtime Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 580.0 KiB
#3 Runtime Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 584.0 KiB
#4 Wrong Answer 77ms 568.0 KiB
#5 Runtime Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 532.0 KiB
#6 Accepted 21ms 616.0 KiB
#7 Wrong Answer 23ms 620.0 KiB
#8 Wrong Answer 4ms 580.0 KiB
#9 Runtime Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 532.0 KiB
#10 Wrong Answer 21ms 600.0 KiB
#11 Runtime Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 580.0 KiB
#12 Wrong Answer 6ms 580.0 KiB
#13 Wrong Answer 20ms 568.0 KiB
#14 Wrong Answer 13ms 572.0 KiB
#15 Wrong Answer 18ms 676.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define       ll           long long
#define       dub          double
#define       ull          unsigned long long
#define       CY           cout << "YES\n"
#define       CN           cout << "NO\n"
#define      allok()      (ios_base:: sync_with_stdio(false),cin.tie(NULL));

//** Number theory --> begin

ll gcd ( ll a, ll b )
{
    if ( b == 0 ) return a;
    else return gcd ( b, a%b );
}
ll lcm ( ll a, ll b )
{
    return (a*b) / gcd(a, b);
}

const ll m = 1e9;
ll mod ( ll a )
{
    return ( (a%m + m) % m );
}
ll madd ( ll a, ll b )
{
    return mod ( mod(a)+mod(b) );
}
ll mmul ( ll a, ll b )
{
    return mod ( mod(a)*mod(b) );
}

//** Number theory --> end


//** Bitwise --> begin

// swap ( x, y ) --> x=x^y, y=x^y, x=x^y
// if x=a then x=b // if x=b then x=a --> x=a^b^x
// a+b=(a^b)+2(a&b)
// a+b=(a|b)+(a&b)

bool checkkthbit ( ll x, ll k )
{
    return (x & (1<<k));  // k'th bit set or not
}
ll setkthbit1 ( ll x, ll k )
{
    return (x | (1<<k));   // make k'th bit 1;
}
ll setkthbit0 ( ll x, ll k )
{
    return (x &~ (1<<k));   // make k'th bit 0;
}
ll mulnumby2powk ( ll x, ll k )
{
    return (x<<k);   // x*(pow(2,k))
}
ll divnumby2powk ( ll x, ll k )
{
    return (x>>k);   // x/pow(2,k)
}
int noofsetbitint ( int x )
{
    return __builtin_popcount(x);  // int set bit count
}
ll noofsetbitll ( ll x )
{
    return __builtin_popcountll(x); // ll set bit count
}
ll togglekthbit ( ll x, ll k )
{                          // if k = 0 then k = 1
    return (x ^ ( 1<<k ));  // if k = 1 then k = 0
}
bool powerof2 ( ll x )
{
    return (x && !(x&(x-1))); // power of 2 checking
}

//** Bitwise --> end


void oddsum ( ll a[], ll x )
{
    ll mio = INT_MAX;
    bool odd = false;
    ll sm = 0;
    for ( ll i=0; i<x; i++ ) {
        if ( a[i] > 0 ) sm += a[i];
        if ( (a[i] & 1) ) {
            odd = true;
            if ( mio > abs ( a[i] ) ) {
                mio = abs ( a[i] );
            }
        }
    }
    if ( !(sm & 1) ) sm -= mio;
    cout << sm << endl;
}

void solve ( )
{
    ll x, y;
    cin >> x >> y;
    vector <string> v(x);
    for ( ll i=0; i<x; i++ ) cin >> v[i];
    while ( y-- ) {
        string maxi = "";
        ll in = -1;
        for ( ll i=0; i<x-1; i++ ) {
            if ( v[i]+v[i+1] > maxi ) {
                maxi = v[i]+v[i+1];
                in = i;
                if ( v[i+1]+v[i] > maxi ) {
                    maxi = v[i+1]+v[i];
                    in = i+1;
                }
            }
        }
        if ( in < v.size()-1 ) {
            if ( v[in-1]+v[in] <= v[in]+v[in+1] ) {
                v[in] += v[in+1];
                v.erase ( v.begin()+in+1 );
            }
            else {
                v[in] += v[in-1];
                v.erase ( v.begin()+in-1 );
            }
        }
    }
    string ans = "";
    for ( auto it: v ) {
        ans = max ( ans, it );
    }
    cout << ans << endl;
}

int main() {

       // allok();
        ll tc, cnt=1;
        cin >> tc;
        while ( tc-- ) solve();


 return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:18:28
Judged At
2024-10-03 13:27:34
Judged By
Score
10
Total Time
77ms
Peak Memory
676.0 KiB