Submission #779523

# Submission time Handle Problem Language Result Execution time Memory
779523 2023-07-11T13:45:37 Z amunduzbaev Mechanical Doll (IOI18_doll) C++17
100 / 100
123 ms 15896 KB
#include "doll.h"
#include "bits/stdc++.h"
using namespace std;

#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
typedef int64_t ll;
typedef int32_t ii;
//~ #define int ll

void create_circuit(ii m, vector<ii> a){
	a.push_back(0);
	int n = a.size(); 
	
	int sz = 1;
	while(sz < n) sz <<= 1;
	vector<int> used(sz * 2);
	function<void(int, int, int)> dfs = [&](int lx, int rx, int x){
		if(rx + n <= sz){
			return;
		}
		used[x] = 1;
		if(lx == rx){
			return;
		}
		
		int m = (lx + rx) >> 1;
		dfs(lx, m, x << 1);
		dfs(m + 1, rx, x << 1 | 1);
	};
	
	dfs(1, sz, 1);
	
	vector<int> sw(sz * 2), pos(sz);
	for(int i=0;i<sz;i++){
		function<void(int, int, int)> go = [&](int x, int lx, int rx){
			if(lx == rx){
				pos[lx] = i;
				return;
			}
			
			int m = (lx + rx) >> 1;
			if(sw[x]) go(x << 1 | 1, m + 1, rx);
			else go(x << 1, lx, m);
			
			sw[x] ^= 1;
		};
		
		go(1, 0, sz - 1);
	}
	
	int last = 0;
	vector<int> id;
	for(int i=0;i<sz;i++){
		if(used[i]){
			used[i] = -(++last);
			id.push_back(i);
		} else {
			used[i] = -1;
		}
	}
	
	fill(used.begin() + sz, used.end(), -1);
	vector<int> p(n); 
	iota(p.begin(), p.end(), sz - n);
	sort(p.begin(), p.end(), [&](int i, int j){
		return pos[i] < pos[j];
	});
	
	for(int i=0;i<n;i++){
		used[sz + p[i]] = a[i];
	}
	
	//~ int lg = 0;
	//~ int tmp = n - 1;
	//~ while(tmp > 1){
		//~ lg++;
		//~ tmp = (tmp + 1) / 2;
	//~ }
	
	//~ assert(last == n - 1 + __lg(n + 1));
	//~ assert(last <= n - 1 + lg);
	//~ assert(last <= 2 * (n - 1));
	
	vector<int> c(m + 1, -1), x(last), y(last);
	for(int i=0;i<last;i++){
		x[i] = used[id[i] << 1];
		y[i] = used[id[i] << 1 | 1];
	}
	
	//~ a.pop_back();
	//~ assert(check(c, x, y, a));
	
	answer(c, x, y);
	
	//~ for(int i=0;i<last;i++){
		//~ cout<<x[i]<<" "<<y[i]<<"\n";
	//~ }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 50 ms 6596 KB Output is correct
3 Correct 46 ms 6088 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 61 ms 7892 KB Output is correct
7 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 50 ms 6596 KB Output is correct
3 Correct 46 ms 6088 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 61 ms 7892 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 96 ms 12264 KB Output is correct
9 Correct 94 ms 12576 KB Output is correct
10 Correct 123 ms 15896 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 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 50 ms 6596 KB Output is correct
3 Correct 46 ms 6088 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 61 ms 7892 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 96 ms 12264 KB Output is correct
9 Correct 94 ms 12576 KB Output is correct
10 Correct 123 ms 15896 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 120 ms 15516 KB Output is correct
15 Correct 90 ms 11896 KB Output is correct
16 Correct 120 ms 15212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 118 ms 15640 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
2 Correct 86 ms 10452 KB Output is correct
3 Correct 86 ms 10576 KB Output is correct
4 Correct 111 ms 13176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 86 ms 10452 KB Output is correct
3 Correct 86 ms 10576 KB Output is correct
4 Correct 111 ms 13176 KB Output is correct
5 Correct 116 ms 13632 KB Output is correct
6 Correct 114 ms 13500 KB Output is correct
7 Correct 115 ms 13552 KB Output is correct
8 Correct 115 ms 13300 KB Output is correct
9 Correct 86 ms 10448 KB Output is correct
10 Correct 111 ms 13276 KB Output is correct
11 Correct 115 ms 13268 KB Output is correct
12 Correct 86 ms 10572 KB Output is correct
13 Correct 89 ms 10748 KB Output is correct
14 Correct 88 ms 10708 KB Output is correct
15 Correct 89 ms 10792 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 63 ms 8388 KB Output is correct
18 Correct 93 ms 10580 KB Output is correct
19 Correct 87 ms 10568 KB Output is correct
20 Correct 112 ms 13292 KB Output is correct
21 Correct 112 ms 13280 KB Output is correct
22 Correct 111 ms 13276 KB Output is correct