답안 #407082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
407082 2021-05-18T12:52:48 Z Antekb 자동 인형 (IOI18_doll) C++14
100 / 100
205 ms 12588 KB
#include "doll.h"
#include<bits/stdc++.h>
using namespace std;

void create_circuit(int M, vector<int> A) {
  	int N = A.size();
  	vector<int> to;
  	if(N==1){
  		vector<int> C(M+1, 0);
  		C[0]=1;
  		answer(C, {}, {});
  		return;
  	}
  	for(int i=0; i<N-1; i++){
  		to.push_back(A[i+1]);
  	}
  	int wsk=-1;
  	vector<int> C(M+1), X, Y;
  	C[0]=A[0];
  	to.push_back(0);
  		int t=1;
  		while(t<to.size())t*=2;
  		vector<int> l(t), r(t), num(t);
  		//cout<<i<<" "<<to[i].size()<<"\n";
  		//for(int j:to[i])cout<<j<<" ";
  		//cout<<"\n";
  		int wsk2=0;
  		for(int j=0; j<t; j++){
  			vector<int> bin;
  			int k=j;
  			while(k>0){
  				bin.push_back(k&1);
  				k>>=1;
  			}
  			bin.resize(__builtin_ctz(t));
  			//reverse(bin.begin(), bin.end());
  			for(int i:bin){
  				k<<=1;
  				k+=i;
  			}
  			//cout<<j<<" "<<k<<"\n";
  			if(k+to.size()>=t && wsk2<to.size()){
  				if(k&1)r[t/2+k/2]=to[wsk2];
  				else l[t/2+k/2]=to[wsk2];
  				wsk2++;
  			}
  			else{
  				if(k&1)r[t/2+k/2]=wsk;
  				else l[t/2+k/2]=wsk;
  			}
  		}
  		//for(int j=0; j<t; j++)cout<<"("<<l[j]<<" "<<r[j]<<") ";
  		//cout<<"\n";
  		vector<int> czy(t);
  		for(int j=t-1; j; j--){
  			if(r[j]==wsk && l[j]==wsk){
  				if(j&1)r[j/2]=l[j];
  				else l[j/2]=l[j];
  				czy[j]=0;
  			}
  			else czy[j]=1;
  		}
  		//for(int j=0; j<t; j++)cout<<czy[j];
  		//cout<<"\n";
  		for(int j=1; j<t; j++)if(czy[j])num[j]=wsk--;
  		for(int j=t-1; j; j--){
  			if(czy[j]){
  				if(j&1)r[j/2]=num[j];
  				else l[j/2]=num[j];
  			}
  		}
  		//for(int j=0; j<t; j++)cout<<"("<<l[j]<<" "<<r[j]<<" "<<num[j]<<") ";
  		//cout<<"\n";
  		X.resize(-wsk-1);
  		Y.resize(-wsk-1);
  		for(int j=1; j<t; j++){
  			if(czy[j]){	
  				X[-1-num[j]]=l[j];
  				Y[-1-num[j]]=r[j];
  			}
  		}
  	for(int i=1; i<=M; i++){
  		C[i]=-1;
  	}
  	/*for(int i:C)cout<<i<<" ";
  	cout<<"\n";
  	for(int i:X)cout<<i<<" ";
  	cout<<"\n";
  	for(int i:Y)cout<<i<<" ";
  	cout<<"\n";*/
  	answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:22:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while(t<to.size())t*=2;
      |           ~^~~~~~~~~~
doll.cpp:42:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |      if(k+to.size()>=t && wsk2<to.size()){
      |         ~~~~~~~~~~~^~~
doll.cpp:42:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |      if(k+to.size()>=t && wsk2<to.size()){
      |                           ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 48 ms 4904 KB Output is correct
3 Correct 69 ms 5436 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 93 ms 7112 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 48 ms 4904 KB Output is correct
3 Correct 69 ms 5436 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 93 ms 7112 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 117 ms 7748 KB Output is correct
9 Correct 135 ms 10184 KB Output is correct
10 Correct 146 ms 12588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 204 KB Output is correct
2 Correct 48 ms 4904 KB Output is correct
3 Correct 69 ms 5436 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 13 ms 1356 KB Output is correct
6 Correct 93 ms 7112 KB Output is correct
7 Correct 2 ms 204 KB Output is correct
8 Correct 117 ms 7748 KB Output is correct
9 Correct 135 ms 10184 KB Output is correct
10 Correct 146 ms 12588 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 186 ms 12132 KB Output is correct
15 Correct 127 ms 9404 KB Output is correct
16 Correct 148 ms 11944 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 2 ms 204 KB Output is correct
20 Correct 205 ms 12332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 77 ms 7100 KB Output is correct
3 Correct 117 ms 9036 KB Output is correct
4 Correct 160 ms 11488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 77 ms 7100 KB Output is correct
3 Correct 117 ms 9036 KB Output is correct
4 Correct 160 ms 11488 KB Output is correct
5 Correct 148 ms 11904 KB Output is correct
6 Correct 169 ms 11620 KB Output is correct
7 Correct 145 ms 11764 KB Output is correct
8 Correct 162 ms 11488 KB Output is correct
9 Correct 127 ms 9020 KB Output is correct
10 Correct 140 ms 11568 KB Output is correct
11 Correct 156 ms 11560 KB Output is correct
12 Correct 121 ms 9048 KB Output is correct
13 Correct 85 ms 7104 KB Output is correct
14 Correct 127 ms 9144 KB Output is correct
15 Correct 130 ms 9248 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 78 ms 7068 KB Output is correct
18 Correct 77 ms 7096 KB Output is correct
19 Correct 116 ms 9020 KB Output is correct
20 Correct 156 ms 11488 KB Output is correct
21 Correct 141 ms 11488 KB Output is correct
22 Correct 136 ms 11560 KB Output is correct