답안 #607548

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
607548 2022-07-26T19:56:29 Z chonka Zalmoxis (BOI18_zalmoxis) C++
65 / 100
167 ms 26548 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

const int MAXN = 1000007 ;

int n , k ;
int a[ MAXN ] ;

stack < int > s ;
vector < pair < int , int > > v ;

void solve ( ) {
    cin >> n >> k ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
    }
    int tp = 0 ; 
    for ( int i = 1 ; i <= n ; ++ i ) {
        int x = a[ i ] ;
        while ( s.empty ( ) == false && s.top ( ) < x ) {
            int y = s.top ( ) ;
            -- k ;
            v.push_back ( { y , 1 } ) ;
            while ( s.empty ( ) == false && s.top ( ) == y ) {
                s.pop ( ) ;
                ++ y ;
            }
            s.push ( y ) ;
        }
        v.push_back ( { x , 0 } ) ;
        while ( s.empty ( ) == false && s.top ( ) == x ) {
            ++ x ; s.pop ( ) ;
        }
        s.push ( x ) ;
    }
    while ( s.empty ( ) == false && s.top ( ) < 30 ) {
        int y = s.top ( ) ;
        -- k ;
        v.push_back ( { y , 1 } ) ;
        while ( s.empty ( ) == false && s.top ( ) == y ) {
            s.pop ( ) ;
            ++ y ;
        }
        s.push ( y ) ;
    }
    for ( auto [ x , type ] : v ) {
        if ( type == 0 ) { cout << x << " " ; }
        else {
            while ( s.empty ( ) == false ) { s.pop ( ) ; }
            s.push ( x ) ;
            while ( k > 0 ) {
                int x = s.top ( ) ; s.pop ( ) ;
                if ( x == 0 ) { cout << "0 " ; }
                else {
                    -- k ;
                    s.push ( x - 1 ) ; s.push ( x - 1 ) ;
                }
            }
            while ( s.empty ( ) == false ) {
                cout << s.top ( ) << " " ;
                s.pop ( ) ;
            }
        }
    }
    cout << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

Compilation message

zalmoxis.cpp: In function 'void solve()':
zalmoxis.cpp:47:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for ( auto [ x , type ] : v ) {
      |                ^
zalmoxis.cpp:18:9: warning: unused variable 'tp' [-Wunused-variable]
   18 |     int tp = 0 ;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 16268 KB Output is correct
2 Correct 167 ms 16300 KB Output is correct
3 Correct 136 ms 16240 KB Output is correct
4 Correct 142 ms 16340 KB Output is correct
5 Correct 137 ms 16268 KB Output is correct
6 Correct 139 ms 16264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 16296 KB Output is correct
2 Correct 156 ms 16292 KB Output is correct
3 Runtime error 74 ms 26548 KB Execution killed with signal 11
4 Correct 141 ms 16300 KB Output is correct
5 Correct 141 ms 16308 KB Output is correct
6 Correct 138 ms 16300 KB Output is correct
7 Correct 152 ms 16240 KB Output is correct
8 Correct 157 ms 16304 KB Output is correct
9 Runtime error 66 ms 23604 KB Execution killed with signal 11
10 Runtime error 29 ms 10508 KB Execution killed with signal 11
11 Runtime error 52 ms 16224 KB Execution killed with signal 11
12 Runtime error 1 ms 468 KB Execution killed with signal 11
13 Runtime error 1 ms 468 KB Execution killed with signal 11
14 Runtime error 1 ms 452 KB Execution killed with signal 11