Submission #107762

#TimeUsernameProblemLanguageResultExecution timeMemory
107762KepperoniSwap (BOI16_swap)C++14
0 / 100
2 ms384 KiB
#include <bits/stdc++.h> #define x first #define y second #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = 2e5 + 10; int n; int a[MAXN]; bool hm[MAXN]; int main(){ cin >> n; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=1; i*2<=n; i++) hm[i]=1; for(int i=2; i<=n; i+=2){ if(i == n){ if(a[i/2] > a[i]) swap(a[i/2], a[i]); } else { if(a[i] < a[i/2] && a[i] < a[i+1]) swap(a[i/2], a[i+1]); else if(a[i+1] < a[i/2]){ if(hm[i] && !hm[i+1]){ if(a[i] < a[i/2]) swap(a[i], a[i/2]); } else { if(a[i] > a[i/2]) swap(a[i], a[i/2]); } swap(a[i+1], a[i/2]); } } } for(int i=1; i<=n; i++) cout << a[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...