Submission #199039

#TimeUsernameProblemLanguageResultExecution timeMemory
199039stefdascaSwap (BOI16_swap)C++14
0 / 100
5 ms424 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 // #define fisier 1 using namespace std; typedef long long ll; int n, v[200002]; int mn(int a, int b) { int va = n+1; if(a > n) va = min(va, n+1); else va = min(va, v[a]); if(b > n) va = min(va, n+1); else va = min(va, v[b]); return va; } int main() { #ifdef fisier ifstream f("input.in"); ofstream g("output.out"); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i) cin >> v[i]; v[n+1] = n+1; for(int i = 1; i + i <= n; ++i) { if(v[i] < v[i+i] && v[i] < v[i+i+1]) continue; if(v[i+i] < v[i] && v[i] < v[i+i+1]) swap(v[i], v[i+i]); else if(v[i+i+1] < v[i] && v[i] < v[i+i]) { if(mn(i*4, i*4+1) > v[i] || (mn(i*4, i*4+1) < v[i] && mn((i+i+1)*2, (i+i+1)*2+1) < v[i+i])) swap(v[i], v[i+i]); swap(v[i+i+1], v[i]); } else if(v[i+i] < v[i+i+1] && v[i+i+1] < v[i]) swap(v[i], v[i+i]); else if(v[i+i+1] < v[i+i] && v[i+i] < v[i]) { if(mn(i*4, i*4+1) < v[i+i] && mn((i+i+1)*2, (i+i+1)*2+1) > v[i+i]) swap(v[i], v[i+i]); swap(v[i+i+1], v[i]); } //for(int j = 1; j <= n; ++j) // cout << v[j] << " "; //cout << '\n'; } for(int i = 1; i <= n; ++i) cout << v[i] << " "; return 0; }
#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...