Submission #670932

#TimeUsernameProblemLanguageResultExecution timeMemory
670932dozerSwap (BOI16_swap)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define sp " " #define endl "\n" #define pii pair<int, int> #define st first #define nd second #define N 100005 #define ai array<int, 3> int arr[N], ans[N], n; int f(int i, int j) { int l = i * 2, r = i * 2 + 1; if (l > n) return j; if (r > n) { int t1 = j; int t2 = arr[l]; int ans = min(t1, t2); return ans; } int t1 = j; int t2 = arr[l]; int t3 = arr[r]; int ans = min(t1, t2); ans = min(ans, t3); return ans; } void print(int i, int j) { int l = i * 2, r = i * 2 + 1; //cout<<i<<sp<<j<<" : "<<l<<sp<<r<<sp<<arr[l]<<sp<<arr[r]<<endl; if (l > n) { ans[i] = j; return; } if (r > n) { ai t1 = {j, f(l, arr[l]), 0}; ai t2 = {arr[l], f(l, j), 0}; if (t1 < t2) { ans[i] = j; print(l, arr[l]); } else { ans[i] = arr[l]; print(l, j); } return; } ai t1 = {j, f(l, arr[l]), f(r, arr[r])}; ai t2 = {arr[l], f(l, j), f(r, arr[r])}; ai t3 = {arr[r], f(l, arr[l]), f(r, j)}; ai t4 = {arr[r], f(l, j), f(r, arr[l])}; ai res = min(t1, t2); res = min(res, t3); res = min(res, t4); if (res == t1) { ans[i] = j; print(l, arr[l]); print(r, arr[r]); return; } if (res == t2) { ans[i] = arr[l]; print(l, j); print(r, arr[r]); return; } if (res == t3) { ans[i] = arr[r]; print(l, arr[l]); print(r, j); return; } if (res == t4) { ans[i] = arr[r]; print(l, j); print(r, arr[l]); return; } } int32_t main() { fastio(); cin>>n; for (int i = 1; i <= n; i++) cin>>arr[i]; print(1, arr[1]); for (int i = 1; i <= n; i++) cout<<ans[i]<<sp; cout<<endl; cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#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...