답안 #767008

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767008 2023-06-26T10:13:58 Z DJeniUp 자동 인형 (IOI18_doll) C++17
53 / 100
159 ms 31044 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

typedef int ll;

#define pb push_back
#define fr first
#define sc second

ll h,a[400007],b[400007],f[400007];

vector<ll>v[200007];

vector<ll>p;

vector<ll>c,x,y;

void create_circuit(int M, std::vector<int> A) {
    A.pb(0);
    for(int i=0;i<A.size()-1;i++){
        v[A[i]].pb(A[i+1]);
    }
    c.pb(A[0]);
    for(int i=1;i<=M;i++){
        if(v[i].size()==0)c.pb(0);
        else if(v[i].size()==1)c.pb(v[i][0]);
        else{
            h++;
            x.pb(-h);
            y.pb(-h);
            c.pb(-h);
            for(int j=0;j<v[i].size();j++){
                ll k=-c[i]-1;
                while(1){
                    if(f[k]%2==0){
                        f[k]++;
                        if(x[k]==-k-1){
                            x[k]=v[i][j];
                            break;
                        }else if(x[k]<0){
                            k=-x[k]-1;
                        }else{
                            h++;
                            f[h-1]=1;
                            x.pb(-h);
                            y.pb(-h);
                            x[h-1]=x[k];
                            x[k]=-h;
                            k=h-1;
                        }
                    }else{
                        f[k]++;
                        if(y[k]==-k-1){
                            y[k]=v[i][j];
                            break;
                        }else if(y[k]<0){
                            k=-y[k]-1;
                        }else{
                            h++;
                            f[h-1]=1;
                            x.pb(-h);
                            y.pb(-h);
                            x[h-1]=y[k];
                            y[k]=-h;
                            k=h-1;
                        }
                    }
                }
            }
        }
    }
    while(1){
        ll k=c[0];
        ll z=0;
        for(int i=0;i<h;i++){
            f[i]=0;
        }
        p.clear();
        ll pr=0;
        while(k!=0){
            pr=k;
            if(k>0){
                k=c[k];
            }else{
                if(f[-k-1]%2==0){
                    p.pb(k);
                    f[-k-1]++;
                    k=x[-k-1];
                }else{

                    f[-k-1]++;
                    k=y[-k-1];
                }
            }
        }
        //cout<<p.back()<<" "<<f[-p.back()-1]<<endl;
        reverse(p.begin(),p.end());
        while(p.size()>0 && f[-p.back()-1]%2==0)p.pop_back();
        if(p.size()==0)break;
        while(p.size()>0){
            while(p.size()>0 && f[-p.back()-1]%2==0)p.pop_back();
            if(p.size()==0)break;
            z=p.back();
            p.pop_back();
            //cout<<z<<endl;
            if(f[-z-1]%2==0){
                break;
            }else{
                if(pr>0)c[pr]=z;
                else{
                    if(f[-pr-1]%2==1)x[-pr-1]=z;
                    else y[-pr-1]=z;
                }
                k=-z-1;
                while(1){
                    pr=-k-1;
                    if(f[k]%2==0){
                        f[k]++;
                        if(x[k]==-k-1){
                            x[k]=0;
                            break;
                        }else if(x[k]<0){
                            k=-x[k]-1;
                        }else{
                            h++;
                            f[h-1]=1;
                            x.pb(-h);
                            y.pb(-h);
                            x[h-1]=x[k];
                            x[k]=-h;
                            k=h-1;
                        }
                    }else{
                        f[k]++;
                        if(y[k]==-k-1){
                            y[k]=0;
                            break;
                        }else if(y[k]<0){
                            k=-y[k]-1;
                        }else{
                            h++;
                            f[h-1]=1;
                            x.pb(-h);
                            y.pb(-h);
                            x[h-1]=y[k];
                            y[k]=-h;
                            k=h-1;
                        }
                    }
                }
            }
        }
    }
    //cout<<c.size()<<" "<<x.size()<<" "<<y.size()<<endl;
    for(int i=0;i<=M;i++){
       // cout<<i<<" "<<c[i]<<endl;
    }
    for(int i=0;i<x.size();i++){
       //if(x[i]==-i-1)swap(x[i],y[i]);
       //cout<<-i-1<<" "<<x[i]<<" "<<y[i]<<endl;
    }
    if(h>2*A.size()-2)exit(1);
    answer(c,x,y);
    return ;
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<A.size()-1;i++){
      |                 ~^~~~~~~~~~~
doll.cpp:33:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             for(int j=0;j<v[i].size();j++){
      |                         ~^~~~~~~~~~~~
doll.cpp:159:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  159 |     for(int i=0;i<x.size();i++){
      |                 ~^~~~~~~~~
doll.cpp:163:9: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  163 |     if(h>2*A.size()-2)exit(1);
      |        ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 21 ms 9132 KB Output is correct
3 Correct 16 ms 8712 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 10 ms 6220 KB Output is correct
6 Correct 24 ms 10572 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 21 ms 9132 KB Output is correct
3 Correct 16 ms 8712 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 10 ms 6220 KB Output is correct
6 Correct 24 ms 10572 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 37 ms 12104 KB Output is correct
9 Correct 47 ms 12480 KB Output is correct
10 Correct 60 ms 15484 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 21 ms 9132 KB Output is correct
3 Correct 16 ms 8712 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 10 ms 6220 KB Output is correct
6 Correct 24 ms 10572 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 37 ms 12104 KB Output is correct
9 Correct 47 ms 12480 KB Output is correct
10 Correct 60 ms 15484 KB Output is correct
11 Correct 2 ms 4948 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 2 ms 4948 KB Output is correct
14 Correct 86 ms 19200 KB Output is correct
15 Correct 40 ms 12568 KB Output is correct
16 Correct 62 ms 15928 KB Output is correct
17 Correct 3 ms 4948 KB Output is correct
18 Correct 3 ms 4948 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 77 ms 17508 KB Output is correct
21 Correct 3 ms 4948 KB Output is correct
22 Correct 3 ms 4948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 4948 KB Output is partially correct
2 Correct 64 ms 17892 KB Output is correct
3 Partially correct 103 ms 22492 KB Output is partially correct
4 Partially correct 159 ms 25280 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 2 ms 4948 KB Output is partially correct
2 Correct 64 ms 17892 KB Output is correct
3 Partially correct 103 ms 22492 KB Output is partially correct
4 Partially correct 159 ms 25280 KB Output is partially correct
5 Partially correct 102 ms 22104 KB Output is partially correct
6 Partially correct 109 ms 26256 KB Output is partially correct
7 Partially correct 122 ms 25480 KB Output is partially correct
8 Partially correct 113 ms 27780 KB Output is partially correct
9 Partially correct 100 ms 23888 KB Output is partially correct
10 Partially correct 142 ms 30596 KB Output is partially correct
11 Partially correct 134 ms 31044 KB Output is partially correct
12 Partially correct 85 ms 21916 KB Output is partially correct
13 Partially correct 72 ms 18568 KB Output is partially correct
14 Partially correct 71 ms 19136 KB Output is partially correct
15 Partially correct 66 ms 17404 KB Output is partially correct
16 Partially correct 4 ms 5392 KB Output is partially correct
17 Partially correct 79 ms 18196 KB Output is partially correct
18 Partially correct 81 ms 18736 KB Output is partially correct
19 Partially correct 80 ms 19704 KB Output is partially correct
20 Partially correct 97 ms 22864 KB Output is partially correct
21 Partially correct 128 ms 27140 KB Output is partially correct
22 Partially correct 108 ms 22488 KB Output is partially correct