Submission #596127

# Submission time Handle Problem Language Result Execution time Memory
596127 2022-07-14T12:00:01 Z FatihSolak Mechanical Doll (IOI18_doll) C++17
100 / 100
147 ms 11100 KB
#include "doll.h"
#include <bits/stdc++.h>
#define N 300005
using namespace std;
int x[N],y[N];
bool last[N];
int add;
void solve(int now,int needed,int num){
	//cout << now << " " << needed << " " << num << endl;
	assert(needed);
	if(num == 2){
		if(needed == 1){
			y[now] = -2;
			x[now] = 1e9;
		}
		if(needed == 2){
			x[now] = 1e9;
			y[now] = 1e9;
		}
		return;
	}
	int nwlen = num/2;
	add++;
	y[now] = -add;
	solve(add,min(needed,nwlen),nwlen);
	needed -= min(needed,nwlen);
	if(needed == 0){
		x[now] = -2;
	}
	else{
		add++;
		x[now] = -add;
		solve(add,min(needed,nwlen),nwlen);
	}
}
void create_circuit(int M, vector<int> A) {
	int n = A.size();
	vector<int> C(M + 1);
	C[0] = A[0];
	for (int i = 1; i <= M; ++i) {
		C[i] = -1;
	}
	if(n == 1){
		C[A[0]] = 0;
		answer(C, {0}, {0});
		return;
	}
	A.push_back(0);
	x[2] = -2;
	y[2] = -1;
	int num = 1;
	while(num < n)
		num *= 2;
	add = 2;
	solve(1,n,num);
	int cnt = 0;
	int pos = 0;
	while(cnt < n){
		//cout << pos << endl;
		if(pos >= 0){
			pos = C[pos];
		}
		else{
			pos *= -1;
			if(last[pos] == 0){
				last[pos] = 1;
				if(x[pos] == 1e9){
					cnt++;
					x[pos] = A[cnt];
				}
				pos = x[pos];
			}
			else{
				last[pos] = 0;
				if(y[pos] == 1e9){
					cnt++;
					y[pos] = A[cnt];
				}
				pos = y[pos];
			}
		}
	}
	vector<int> X,Y;
	for(int i = 1;i<=add;i++){
		X.push_back(x[i]);
		Y.push_back(y[i]);
	}
	// for(auto u:C){
	// 	cout << u << " ";
	// }
	// cout << endl;
	// for(auto u:X){
	// 	cout << u << " ";
	// }
	// cout << endl;
	// for(auto u:Y){
	// 	cout << u << " ";
	// }
	// cout << endl;
	answer(C,X,Y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4672 KB Output is correct
3 Correct 35 ms 4676 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 56 ms 6608 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4672 KB Output is correct
3 Correct 35 ms 4676 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 56 ms 6608 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 84 ms 8456 KB Output is correct
9 Correct 73 ms 7668 KB Output is correct
10 Correct 108 ms 11100 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 4672 KB Output is correct
3 Correct 35 ms 4676 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 9 ms 1492 KB Output is correct
6 Correct 56 ms 6608 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 84 ms 8456 KB Output is correct
9 Correct 73 ms 7668 KB Output is correct
10 Correct 108 ms 11100 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 117 ms 10808 KB Output is correct
15 Correct 86 ms 6908 KB Output is correct
16 Correct 118 ms 10548 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 114 ms 10896 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 60 ms 7456 KB Output is correct
3 Correct 80 ms 6412 KB Output is correct
4 Correct 103 ms 9772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 60 ms 7456 KB Output is correct
3 Correct 80 ms 6412 KB Output is correct
4 Correct 103 ms 9772 KB Output is correct
5 Correct 147 ms 10464 KB Output is correct
6 Correct 125 ms 10256 KB Output is correct
7 Correct 114 ms 10476 KB Output is correct
8 Correct 114 ms 10084 KB Output is correct
9 Correct 68 ms 6388 KB Output is correct
10 Correct 112 ms 9976 KB Output is correct
11 Correct 115 ms 9764 KB Output is correct
12 Correct 66 ms 6428 KB Output is correct
13 Correct 76 ms 7948 KB Output is correct
14 Correct 95 ms 6792 KB Output is correct
15 Correct 89 ms 6952 KB Output is correct
16 Correct 4 ms 476 KB Output is correct
17 Correct 66 ms 7704 KB Output is correct
18 Correct 66 ms 7636 KB Output is correct
19 Correct 71 ms 6512 KB Output is correct
20 Correct 117 ms 9920 KB Output is correct
21 Correct 101 ms 9704 KB Output is correct
22 Correct 104 ms 9712 KB Output is correct