답안 #762055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
762055 2023-06-20T17:17:06 Z LucaIlie Zalmoxis (BOI18_zalmoxis) C++17
20 / 100
519 ms 78316 KB
#include <bits/stdc++.h>

using namespace std;

struct xxx {
    int l, r, val, ap;

    bool operator < ( const xxx &x ) const {
        if ( val == x.val )
            return l < x.l;
        return val < x.val;
    }
};

const int MAX_N = 1e6;
int v[MAX_N + 2], leftt[MAX_N + 2], rightt[MAX_N + 2], value[MAX_N + 2], apar[MAX_N + 2];
set<xxx> seg;
vector<int> adaugiri[MAX_N + 1];

int main() {
    int n, k;

    cin >> n >> k;
    for ( int i = 1; i <= n; i++ )
        cin >> v[i];

    int l = 1, r = 1;
    while ( l <= n ) {
        r = l;
        while ( r + 1 <= n && v[l] == v[r + 1] )
            r++;
        leftt[l] = leftt[r] = l;
        rightt[l] = rightt[r] = r;
        value[l] = value[r] = v[l];
        apar[l] = apar[r] = r - l + 1;
        seg.insert( { l, r, v[l], r - l + 1 } );
        l = r + 1;
    }

    value[0] = value[n + 1] = -1;
    while ( !(seg.size() == 1 && seg.begin()->ap == 1) ) {
        int l = seg.begin()->l, r = seg.begin()->r, val = seg.begin()->val, ap = seg.begin()->ap;
        seg.erase( { l, r, val, ap } );

        if ( ap % 2 == 1 ) {
            ap++;
            k--;
            adaugiri[r].push_back( val );
        }
        ap /= 2;
        val++;

        if ( val == value[l - 1] ) {
            ap += apar[l - 1];
            seg.erase( { leftt[l - 1], rightt[l - 1], value[l - 1], apar[l - 1] } );
            l = leftt[l - 1];
        }
        if ( val == value[r + 1] ) {
            ap += apar[r + 1];
            seg.erase( { leftt[r + 1], rightt[r + 1], value[r + 1], apar[r + 1] } );
            r = rightt[r + 1];
        }

        leftt[l] = leftt[r] = l;
        rightt[l] = rightt[r] = r;
        value[l] = value[r] = val;
        apar[l] = apar[r] = ap;
        seg.insert( { l, r, val, ap } );
    }

    for ( int i = 1; i <= n; i++ ) {
        cout << v[i] << " ";
        for ( int x: adaugiri[i] )
            cout << x << " ";
    }
    
    int val = seg.begin()->val;
    
    if ( val == 30 && k == 0 )
        return 1;
    
    for ( ; val < 29; val++ ) {
        cout << val << " ";
        k--;
    }
    for ( int b = 19; b >= 0; b-- ) {
        if ( k >= (1 << b) ) {
            k -= (1 << b);
            if ( k > 0 )
                val--;
            for ( int i = 0; i < (1 << b); i++ )
                cout << val - b << " ";
        }
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 468 ms 77252 KB Execution failed because the return code was nonzero
2 Runtime error 473 ms 78072 KB Execution failed because the return code was nonzero
3 Runtime error 498 ms 77608 KB Execution failed because the return code was nonzero
4 Runtime error 469 ms 77792 KB Execution failed because the return code was nonzero
5 Runtime error 462 ms 77896 KB Execution failed because the return code was nonzero
6 Runtime error 455 ms 76804 KB Execution failed because the return code was nonzero
# 결과 실행 시간 메모리 Grader output
1 Incorrect 463 ms 77604 KB not a zalsequence
2 Runtime error 437 ms 76748 KB Execution failed because the return code was nonzero
3 Incorrect 465 ms 78016 KB not a zalsequence
4 Incorrect 483 ms 78096 KB not a zalsequence
5 Incorrect 484 ms 77632 KB not a zalsequence
6 Incorrect 451 ms 77472 KB not a zalsequence
7 Incorrect 469 ms 77940 KB not a zalsequence
8 Incorrect 519 ms 78316 KB not a zalsequence
9 Incorrect 432 ms 69916 KB not a zalsequence
10 Correct 229 ms 45180 KB Output is correct
11 Incorrect 324 ms 55912 KB not a zalsequence
12 Correct 66 ms 25704 KB Output is correct
13 Correct 64 ms 25804 KB Output is correct
14 Correct 67 ms 25764 KB Output is correct