Submission #27104

#TimeUsernameProblemLanguageResultExecution timeMemory
27104tlwpdusSwap (BOI16_swap)C++11
100 / 100
79 ms6708 KiB
#include <bits/stdc++.h> using namespace std; int n, arr[400100], brr[400100], used[400100], INF = 987654321; int getv(int idx) { int res = INF; while(idx>0) { if (used[idx]!=1) res = min(res,arr[idx]); if (!used[idx]) break; if ((idx&1)&&used[idx^1]) { res = min(res,arr[idx^1]); if (used[idx^1]==1) break; } idx>>=1; } return res; } void era(int idx, int val) { while(idx>0) { if (arr[idx]==val) { used[idx] = 0; break; } if (idx&1) { if (arr[idx^1]==val) { used[idx^1] = used[idx] = 1; break; } else used[idx^1] = 0; } used[idx] = 1; idx>>=1; } } int main() { int i; scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d",&arr[i]); for (i=1;i<=n;i++) used[i] = 2; used[1] = 0; for (i=1;i<=n;i++) { int res = getv(i), l = ((i*2<=n)?arr[i*2]:INF), r = ((i*2+1<=n)?arr[i*2+1]:INF); int v = min({res,l,r}); if (res==v) { used[i*2] = used[i*2+1] = 0; era(i,res); } else if (l==v) {used[i*2+1] = 0; used[i*2] = 1;} else used[i*2+1] = 1; brr[i] = v; } for (i=1;i<=n;i++) printf("%d ",brr[i]); printf("\n"); return 0; }

Compilation message (stderr)

swap.cpp: In function 'int main()':
swap.cpp:42:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
swap.cpp:43:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i=1;i<=n;i++) scanf("%d",&arr[i]);
                                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...