답안 #719599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719599 2023-04-06T10:44:11 Z bin9638 자동 인형 (IOI18_doll) C++17
53 / 100
166 ms 71548 KB
#include <bits/stdc++.h>

#ifndef SKY
#include "doll.h"
#endif // SKY

using namespace std;

#define N  1000010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back

int n,q,dem=0,root[N];
vector<int>lis[N];
vector<ii>flow_out[N];
vector<int>a,C,X,Y;

#ifdef SKY
void answer(vector<int>C,vector<int>X,vector<int>Y)
{
    for(auto u:C)cout<<u<<" ";cout<<endl;
    for(int i=0;i<X.size();i++)cout<<X[i]<<" "<<Y[i]<<endl;
}
#endif // SKY

struct haha
{
    int child[2]={},tt=0;
}node[N];

void build(int u,int h)
{
    if(h==0)
        return;
    node[u].child[0]=++dem;
    node[u].child[1]=++dem;
    build(node[u].child[0],h-1);
    build(node[u].child[1],h-1);
}

ii DFS(int u)
{
    if(node[u].child[0]==0)
    {
        ii res={u,node[u].tt};
        node[u].tt^=1;
        return res;
    }
    node[u].tt^=1;
    return DFS(node[u].child[(node[u].tt^1)]);
}

void solve(int u)
{
    int k=ceil(log2(lis[u].size()));
    dem++;
    C[u]=-dem;
    int moc=dem;
    root[u]=moc;
    build(moc,k-1);
    while(1)
    {
        ii cc=DFS(moc);
        if(!flow_out[u].empty()&&cc==flow_out[u][0])
            break;
        //cout<<"cc\n";
        flow_out[u].pb(cc);
    }
    for(auto cc:flow_out[u])
        node[cc.fs].child[cc.sc]=moc;
    int pos=dem;
    while(!lis[u].empty())
    {
        ii cc=flow_out[u].back();
        flow_out[u].pop_back();
        int i=lis[u].back();
        lis[u].pop_back();
        if(i==q-1)
        {
            node[cc.fs].child[cc.sc]=0;
        }else
        {
            node[cc.fs].child[cc.sc]=-a[i+1];
        }
    }
}

void create_circuit(int cc, vector<int> vec)
{
    a=vec;
    n=cc;
    q=a.size();
  //  cout<<m<<" "<<n<<endl;
    for(int i=0;i<q;i++)
        lis[a[i]].pb(i);
   // for(int i=1;i<=n;i++)cout<<lis[i].size()<<endl;
    C.resize(n+1,0);
    C[0]=a[0];
    for(int i=1;i<=n;i++)
        if(!lis[i].empty())
        {
            if(lis[i].size()==1)
            {
                if(lis[i].back()!=q-1)
                    C[i]=a[lis[i].back()+1];
                continue;
            }
            solve(i);
        }
    for(int i=1;i<=dem;i++)
        X.pb(-node[i].child[0]),Y.pb(-node[i].child[1]);
    answer(C,X,Y);
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int m,n;
    cin>>m>>n;
    vector<int>a;
    for(int i=1;i<=n;i++)
    {
        int u;
        cin>>u;
        a.pb(u);
    }
    create_circuit(m,a);
    return 0;
}
#endif

Compilation message

doll.cpp: In function 'void solve(int)':
doll.cpp:74:9: warning: unused variable 'pos' [-Wunused-variable]
   74 |     int pos=dem;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47188 KB Output is correct
2 Correct 45 ms 51408 KB Output is correct
3 Correct 44 ms 51032 KB Output is correct
4 Correct 23 ms 47188 KB Output is correct
5 Correct 38 ms 48380 KB Output is correct
6 Correct 70 ms 52868 KB Output is correct
7 Correct 24 ms 47192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47188 KB Output is correct
2 Correct 45 ms 51408 KB Output is correct
3 Correct 44 ms 51032 KB Output is correct
4 Correct 23 ms 47188 KB Output is correct
5 Correct 38 ms 48380 KB Output is correct
6 Correct 70 ms 52868 KB Output is correct
7 Correct 24 ms 47192 KB Output is correct
8 Correct 76 ms 56520 KB Output is correct
9 Correct 86 ms 57036 KB Output is correct
10 Correct 99 ms 62608 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 27 ms 47276 KB Output is correct
13 Correct 26 ms 47260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 47188 KB Output is correct
2 Correct 45 ms 51408 KB Output is correct
3 Correct 44 ms 51032 KB Output is correct
4 Correct 23 ms 47188 KB Output is correct
5 Correct 38 ms 48380 KB Output is correct
6 Correct 70 ms 52868 KB Output is correct
7 Correct 24 ms 47192 KB Output is correct
8 Correct 76 ms 56520 KB Output is correct
9 Correct 86 ms 57036 KB Output is correct
10 Correct 99 ms 62608 KB Output is correct
11 Correct 24 ms 47188 KB Output is correct
12 Correct 27 ms 47276 KB Output is correct
13 Correct 26 ms 47260 KB Output is correct
14 Correct 117 ms 65160 KB Output is correct
15 Correct 71 ms 56460 KB Output is correct
16 Correct 106 ms 61300 KB Output is correct
17 Correct 23 ms 47188 KB Output is correct
18 Correct 22 ms 47172 KB Output is correct
19 Correct 24 ms 47248 KB Output is correct
20 Correct 142 ms 63404 KB Output is correct
21 Correct 25 ms 47188 KB Output is correct
22 Correct 23 ms 47228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 47188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 22 ms 47172 KB Output is partially correct
2 Correct 83 ms 56896 KB Output is correct
3 Partially correct 161 ms 64020 KB Output is partially correct
4 Partially correct 143 ms 65228 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 22 ms 47172 KB Output is partially correct
2 Correct 83 ms 56896 KB Output is correct
3 Partially correct 161 ms 64020 KB Output is partially correct
4 Partially correct 143 ms 65228 KB Output is partially correct
5 Partially correct 131 ms 68072 KB Output is partially correct
6 Partially correct 137 ms 69836 KB Output is partially correct
7 Partially correct 145 ms 69308 KB Output is partially correct
8 Partially correct 138 ms 70816 KB Output is partially correct
9 Partially correct 154 ms 62064 KB Output is partially correct
10 Partially correct 166 ms 70500 KB Output is partially correct
11 Partially correct 143 ms 71548 KB Output is partially correct
12 Partially correct 103 ms 63124 KB Output is partially correct
13 Partially correct 95 ms 62068 KB Output is partially correct
14 Partially correct 102 ms 61484 KB Output is partially correct
15 Partially correct 94 ms 60828 KB Output is partially correct
16 Partially correct 25 ms 47684 KB Output is partially correct
17 Partially correct 87 ms 59864 KB Output is partially correct
18 Partially correct 87 ms 59864 KB Output is partially correct
19 Partially correct 98 ms 60732 KB Output is partially correct
20 Partially correct 112 ms 64956 KB Output is partially correct
21 Partially correct 135 ms 68456 KB Output is partially correct
22 Partially correct 111 ms 63784 KB Output is partially correct