Submission #27098

#TimeUsernameProblemLanguageResultExecution timeMemory
27098tlwpdusSwap (BOI16_swap)C++11
68 / 100
59 ms4364 KiB
#include <bits/stdc++.h> using namespace std; int n; int arr[200100]; int brr[200100]; int used[200100]; int getv(int idx) { int res = 987654321; while(idx>0) { if (used[idx]!=1) res = min(res,arr[idx]); if (!used[idx]) break; if (idx&1) { if (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]:987654321), r = ((i*2+1<=n)?arr[i*2+1]:987654321); 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:47:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
swap.cpp:48: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...