Submission #258566

# Submission time Handle Problem Language Result Execution time Memory
258566 2020-08-06T07:05:43 Z 최은수(#5046) Swap (BOI16_swap) C++17
0 / 100
0 ms 384 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int v[400010],ans[200010];
bool chk[200010];
int type[200010]; // 1 left 2 right
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=0;i++<n;)
        cin>>v[i];
    for(int i=n;i++<n*2+1;)
        v[i]=n+1;
    for(int i=0;i++<n;)
    {
        int j=i*2;
        int k=i*2+1;
        int mn=chk[v[i]]?n:v[i];
        for(int p=i;p>1;p/=2)
        {
            if(p%2==1&&(type[p/2]==0||type[p/2]==1)&&!chk[v[p^1]])
                mn=min(mn,v[p^1]);
            if(type[p/2]!=0&&type[p/2]!=p%2+1)
                break;
            if(!chk[v[p/2]])
                mn=min(mn,v[p/2]);
        }
        ans[i]=min({mn,v[j],v[k]});
        if(ans[i]==mn)
        {
            int tp=0;
            int id=0;
            for(int p=i;p>1;p/=2)
            {
                if(p%2==1&&v[p^1]==mn)
                    tp=1,id=p;
                if(v[p/2]==mn)
                    tp=2,id=p;
            }
            if(type[id/2]==0)
                type[id/2]=tp;
            type[i]=3;
        }
        else if(ans[i]==v[j])
            type[i]=1;
        else
            type[i]=0;
        chk[ans[i]]=1;
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -