# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
199037 | 2020-01-28T17:57:48 Z | TadijaSebez | Swap (BOI16_swap) | C++11 | 76 ms | 6904 KB |
#include <bits/stdc++.h> using namespace std; void ckmn(int &a,int b){a=min(a,b);} const int N=400050; int a[N],t[N],ans[N]; int Get(int i){ int ans=1e9; for(;i;i>>=1){ if(t[i]!=1)ckmn(ans,a[i]); if(t[i]==0)break; if((i&1) && t[i^1]!=0){ ckmn(ans,a[i^1]); if(t[i^1]==1)break; } } return ans; } void Set(int i,int f){ for(;i;i>>=1){ if(a[i]==f){ t[i]=0; break; } if(i&1){ if(a[i^1]==f){ t[i]=t[i^1]=1; break; }else t[i^1]=0; } t[i]=1; } } int main(){ int n; scanf("%i",&n); for(int i=1;i<=n;i++)scanf("%i",&a[i]),t[i]=2; t[1]=0; for(int i=n+1;i<=n*2+1;i++)a[i]=1e9; for(int i=1;i<=n;i++){ int gt=Get(i); ans[i]=min({a[i<<1],a[i<<1|1],gt}); if(ans[i]==gt) t[i<<1]=0, t[i<<1|1]=0, Set(i,gt); if(ans[i]==a[i<<1]) t[i<<1]=1, t[i<<1|1]=0; if(ans[i]==a[i<<1|1]) t[i<<1|1]=1; } for(int i=1;i<=n;i++)printf("%i%c",ans[i],i==n?'\n':' '); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 23 ms | 1912 KB | Output is correct |
17 | Correct | 21 ms | 1912 KB | Output is correct |
18 | Correct | 20 ms | 1912 KB | Output is correct |
19 | Correct | 22 ms | 1916 KB | Output is correct |
20 | Correct | 22 ms | 1912 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 5 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 5 ms | 376 KB | Output is correct |
12 | Correct | 5 ms | 376 KB | Output is correct |
13 | Correct | 5 ms | 376 KB | Output is correct |
14 | Correct | 5 ms | 376 KB | Output is correct |
15 | Correct | 5 ms | 376 KB | Output is correct |
16 | Correct | 23 ms | 1912 KB | Output is correct |
17 | Correct | 21 ms | 1912 KB | Output is correct |
18 | Correct | 20 ms | 1912 KB | Output is correct |
19 | Correct | 22 ms | 1916 KB | Output is correct |
20 | Correct | 22 ms | 1912 KB | Output is correct |
21 | Correct | 68 ms | 6776 KB | Output is correct |
22 | Correct | 70 ms | 6904 KB | Output is correct |
23 | Correct | 68 ms | 6904 KB | Output is correct |
24 | Correct | 73 ms | 6776 KB | Output is correct |
25 | Correct | 76 ms | 6776 KB | Output is correct |