# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
607552 | chonka | Zalmoxis (BOI18_zalmoxis) | C++98 | 156 ms | 14296 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 && s.empty ( ) == false ) {
int hh = s.top ( ) ; s.pop ( ) ;
if ( hh == 0 ) { cout << "0 " ; }
else {
-- k ;
s.push ( hh - 1 ) ; s.push ( hh - 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 ;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |