# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
563766 | 2022-05-18T05:38:27 Z | Dymo | Swap (BOI16_swap) | C++14 | 52 ms | 9068 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn=4e5+10; const ll mod=1e9+7 ; const ll base=2e9; ll n; ll a[maxn]; ll st[maxn]; ll get(ll u) { if (st[u]==0) return a[u]; else if (u%2==1) { assert(st[u]==1); if (st[u-1]==0) return get(u/2); else if (st[u-1]==1) return a[u-1]; else if (st[u-1]==2) return min(get(u/2),a[u-1]); } else { if (st[u]==1) { return get(u/2); } else { return min(get(u/2),a[u]); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("test.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } memset(a,0x3f,sizeof(a)); // cout <<a[0]<<endl; cin>> n; for (int i=1;i<=n;i++) { cin>> a[i]; } for (int i=1;i<=n;i++) { pll val=min(make_pair(a[i*2],i*2),make_pair(a[i*2+1],i*2+1)); ll valnw=get(i); // cout <<valnw<<" "<<val.ff<<" "<<val.ss<<" chk1"<<endl; /*if (i==2) { cout <<valnw<<" "<<i<<" "<<st[i]<<" "<<a[i]<<" "<<i/2<<" "<<st[i/2]<<" "<<a[i/2]<<endl; }*/ if (val.ff>valnw) { cout <<valnw<<" "; ll u=i; while (1) { if (st[u]==0) break; else if (u%2==1) { assert(st[u]==1); if (st[u-1]==0) { u/=2; } else if (st[u-1]==1) { assert(valnw==a[u-1]); break; } else if (st[u-1]==2) { if (valnw==a[u-1]) { st[u-1]=1; break; } st[u-1]=0; u/=2; } } else { if (st[u]==2) { if (a[u]==valnw) { st[u]=0; break; } else { st[u]=1; u/=2; } } else { u/=2; } } } st[i*2]=0; st[i*2+1]=0; } else { cout <<val.ff<<" "; if (val.ss==i*2) { st[i*2]=1; st[i*2+1]=0; } else { st[i*2]=2; st[i*2+1]=1; } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3412 KB | Output is correct |
2 | Correct | 2 ms | 3412 KB | Output is correct |
3 | Correct | 2 ms | 3412 KB | Output is correct |
4 | Correct | 2 ms | 3412 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3412 KB | Output is correct |
2 | Correct | 2 ms | 3412 KB | Output is correct |
3 | Correct | 2 ms | 3412 KB | Output is correct |
4 | Correct | 2 ms | 3412 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
6 | Correct | 2 ms | 3412 KB | Output is correct |
7 | Correct | 2 ms | 3412 KB | Output is correct |
8 | Correct | 2 ms | 3412 KB | Output is correct |
9 | Correct | 2 ms | 3412 KB | Output is correct |
10 | Correct | 2 ms | 3412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3412 KB | Output is correct |
2 | Correct | 2 ms | 3412 KB | Output is correct |
3 | Correct | 2 ms | 3412 KB | Output is correct |
4 | Correct | 2 ms | 3412 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
6 | Correct | 2 ms | 3412 KB | Output is correct |
7 | Correct | 2 ms | 3412 KB | Output is correct |
8 | Correct | 2 ms | 3412 KB | Output is correct |
9 | Correct | 2 ms | 3412 KB | Output is correct |
10 | Correct | 2 ms | 3412 KB | Output is correct |
11 | Correct | 2 ms | 3412 KB | Output is correct |
12 | Correct | 3 ms | 3412 KB | Output is correct |
13 | Correct | 2 ms | 3412 KB | Output is correct |
14 | Correct | 2 ms | 3412 KB | Output is correct |
15 | Correct | 2 ms | 3464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3412 KB | Output is correct |
2 | Correct | 2 ms | 3412 KB | Output is correct |
3 | Correct | 2 ms | 3412 KB | Output is correct |
4 | Correct | 2 ms | 3412 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
6 | Correct | 2 ms | 3412 KB | Output is correct |
7 | Correct | 2 ms | 3412 KB | Output is correct |
8 | Correct | 2 ms | 3412 KB | Output is correct |
9 | Correct | 2 ms | 3412 KB | Output is correct |
10 | Correct | 2 ms | 3412 KB | Output is correct |
11 | Correct | 2 ms | 3412 KB | Output is correct |
12 | Correct | 3 ms | 3412 KB | Output is correct |
13 | Correct | 2 ms | 3412 KB | Output is correct |
14 | Correct | 2 ms | 3412 KB | Output is correct |
15 | Correct | 2 ms | 3464 KB | Output is correct |
16 | Correct | 12 ms | 4752 KB | Output is correct |
17 | Correct | 12 ms | 4688 KB | Output is correct |
18 | Correct | 12 ms | 4772 KB | Output is correct |
19 | Correct | 14 ms | 4820 KB | Output is correct |
20 | Correct | 13 ms | 4692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3412 KB | Output is correct |
2 | Correct | 2 ms | 3412 KB | Output is correct |
3 | Correct | 2 ms | 3412 KB | Output is correct |
4 | Correct | 2 ms | 3412 KB | Output is correct |
5 | Correct | 2 ms | 3412 KB | Output is correct |
6 | Correct | 2 ms | 3412 KB | Output is correct |
7 | Correct | 2 ms | 3412 KB | Output is correct |
8 | Correct | 2 ms | 3412 KB | Output is correct |
9 | Correct | 2 ms | 3412 KB | Output is correct |
10 | Correct | 2 ms | 3412 KB | Output is correct |
11 | Correct | 2 ms | 3412 KB | Output is correct |
12 | Correct | 3 ms | 3412 KB | Output is correct |
13 | Correct | 2 ms | 3412 KB | Output is correct |
14 | Correct | 2 ms | 3412 KB | Output is correct |
15 | Correct | 2 ms | 3464 KB | Output is correct |
16 | Correct | 12 ms | 4752 KB | Output is correct |
17 | Correct | 12 ms | 4688 KB | Output is correct |
18 | Correct | 12 ms | 4772 KB | Output is correct |
19 | Correct | 14 ms | 4820 KB | Output is correct |
20 | Correct | 13 ms | 4692 KB | Output is correct |
21 | Correct | 43 ms | 9040 KB | Output is correct |
22 | Correct | 48 ms | 9024 KB | Output is correct |
23 | Correct | 40 ms | 9036 KB | Output is correct |
24 | Correct | 52 ms | 9068 KB | Output is correct |
25 | Correct | 50 ms | 9052 KB | Output is correct |