답안 #258581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258581 2020-08-06T07:30:35 Z 최은수(#5046) Swap (BOI16_swap) C++17
100 / 100
141 ms 6008 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];
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;
        vector<int>vv;
        for(int p=i;p>1;p/=2)
        {
            if(type[p/2]==0);
            else if(type[p/2]==1&&p%2==0);
            else if(type[p/2]==2&&p%2==1);
            else if(type[p/2]==4);
            else
                break;
            vv.eb(p);
        }
        reverse(all(vv));
        int mn=!vv.empty()?v[vv[0]/2]:v[i];
        for(int&p:vv)
        {
            if(type[p/2]==0)
            {
                if(p%2==0)
                    mn=min(mn,v[p]);
                else
                    mn=min(mn,v[p^1]);
            }
            else if(type[p/2]==1);
            else if(type[p/2]==2);
            else if(p%2==0);
            else
                mn=v[p^1];
        }
        ans[i]=min({mn,v[j],v[k]});
        if(ans[i]==mn)
        {
            int mn2=!vv.empty()?v[vv[0]/2]:v[i];
            for(int&p:vv)
            {
                if(type[p/2]==0)
                {
                    if(p%2==0)
                    {
                        if(mn2==mn||v[p]==mn)
                            type[p/2]=mn2==mn?4:2;
                        mn2=min(mn2,v[p]);
                    }
                    else
                    {
                        if(mn2==mn||v[p^1]==mn)
                            type[p/2]=mn2==mn?2:4;
                        mn2=min(mn2,v[p^1]);
                    }
                }
                else if(type[p/2]==1);
                else if(type[p/2]==2);
                else if(p%2==0);
                else
                    mn2=v[p^1];
            }
            type[i]=3;
        }
        else if(ans[i]==v[j])
            type[i]=1;
        else
            type[i]=0;
        cout<<ans[i]<<' ';
    }
    cout<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 1664 KB Output is correct
17 Correct 15 ms 1664 KB Output is correct
18 Correct 16 ms 1664 KB Output is correct
19 Correct 28 ms 1656 KB Output is correct
20 Correct 29 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 1664 KB Output is correct
17 Correct 15 ms 1664 KB Output is correct
18 Correct 16 ms 1664 KB Output is correct
19 Correct 28 ms 1656 KB Output is correct
20 Correct 29 ms 1664 KB Output is correct
21 Correct 66 ms 6008 KB Output is correct
22 Correct 64 ms 6008 KB Output is correct
23 Correct 65 ms 6008 KB Output is correct
24 Correct 141 ms 6008 KB Output is correct
25 Correct 130 ms 6008 KB Output is correct