Submission #793854

# Submission time Handle Problem Language Result Execution time Memory
793854 2023-07-26T07:27:56 Z NothingXD Mechanical Doll (IOI18_doll) C++17
85.553 / 100
141 ms 22552 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;

void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 4e5 + 10;

int n, m, a[maxn], out[maxn], out1[maxn], out2[maxn], res;
vector<int> idx[maxn];

void solve(int v, int root, vector<int> tmp){
//	debug(v);
//	for (auto x: tmp) debug(x);
	vector<int> l;
	vector<int> r;
	for (int i = 0; i < tmp.size(); i++){
		if (i&1) r.push_back(tmp[i]);
		else l.push_back(tmp[i]);
	}
	bool flgl = false;
	bool flgr = false;
	for (auto x: l) if (x != -1) flgl = true;
	for (auto x: r) if (x != -1) flgr = true;
	if (!flgl){
		out1[v-1] = -root;
	}
	else if (l.size() == 1){
		out1[v-1] = a[l[0]+1];
	}
	else{
		res++;
		out1[v-1] = -res;
		solve(res, root, l);
	}
	if (!flgr){
		out2[v-1] = -root;
	}
	else if (r.size() == 1){
		out2[v-1] = a[r[0]+1];
	}
	else{
		res++;
		out2[v-1] = -res;
		solve(res, root, r);
	}
}

vector<int> Calc(int l, int r){
//	debug(l, r);
	if (l + 1 == r){
		return vector<int>{l};
	}
	int mid = (l + r) >> 1;
	vector<int> lc = Calc(l, mid);
	vector<int> rc = Calc(mid, r);
	vector<int> ans;
	for (int i = 0; i < lc.size(); i++){
		ans.push_back(lc[i]);
		ans.push_back(rc[i]);
	}
	return ans;
}

void create_circuit(int M, vector<int> A) {
	n = A.size(); m = M;
	for (int i = 0; i < n; i++){
		a[i] = A[i];
		idx[a[i]].push_back(i);
	}
	a[n] = 0;
	out[0] = a[0];
	for (int i = 1; i <= m; i++){
		int tmp = idx[i].size();
		if (tmp == 0){
			out[i] = 0;
			continue;
		
		}
		while(tmp % 2 == 0) tmp /= 2;
		vector<int> bad;
		while(tmp != 1){
			bad.push_back(-1);
			tmp = idx[i].size() + bad.size();
			while(tmp % 2 == 0) tmp /= 2;
		}
		int sz = idx[i].size() + bad.size();
		if (sz == 1){
			out[i] = a[idx[i][0]+1];
			continue;
		}
		reverse(all(idx[i]));
		vector<int> val;
	//	debug(sz);
		vector<int> ptr = Calc(0, sz);
	//	debug(i, ptr.size(), bad.size());
		int sz2 = idx[i].size();
		for (int j = 0; j < sz; j++){
			if (ptr[j] >= bad.size()){
				val.push_back(idx[i].back());
				idx[i].pop_back();
			}
			else{
				val.push_back(-1);
			}
		}
		res++;
		out[i] = -res;
		solve(res, res, val);
	}
	vector<int> C(m+1), X(res), Y(res);
	for (int i = 0; i <= m; i++){
		C[i] = out[i];
		//debug(i, C[i]);
	}
	//debug(res);
	for (int i = 0; i < res; i++){
		X[i] = out1[i];
		Y[i] = out2[i];
	//	debug(-(i+1), X[i], Y[i]);
	}
	answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void solve(int, int, std::vector<int>)':
doll.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (int i = 0; i < tmp.size(); i++){
      |                  ~~^~~~~~~~~~~~
doll.cpp: In function 'std::vector<int> Calc(int, int)':
doll.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for (int i = 0; i < lc.size(); i++){
      |                  ~~^~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:117:15: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |    if (ptr[j] >= bad.size()){
doll.cpp:115:7: warning: unused variable 'sz2' [-Wunused-variable]
  115 |   int sz2 = idx[i].size();
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 25 ms 14036 KB Output is correct
3 Correct 20 ms 13524 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 12 ms 11220 KB Output is correct
6 Correct 29 ms 15572 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 25 ms 14036 KB Output is correct
3 Correct 20 ms 13524 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 12 ms 11220 KB Output is correct
6 Correct 29 ms 15572 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 49 ms 16412 KB Output is correct
9 Correct 48 ms 16832 KB Output is correct
10 Correct 93 ms 19832 KB Output is correct
11 Correct 5 ms 9636 KB Output is correct
12 Correct 4 ms 9684 KB Output is correct
13 Correct 4 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 25 ms 14036 KB Output is correct
3 Correct 20 ms 13524 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 12 ms 11220 KB Output is correct
6 Correct 29 ms 15572 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 49 ms 16412 KB Output is correct
9 Correct 48 ms 16832 KB Output is correct
10 Correct 93 ms 19832 KB Output is correct
11 Correct 5 ms 9636 KB Output is correct
12 Correct 4 ms 9684 KB Output is correct
13 Correct 4 ms 9684 KB Output is correct
14 Correct 103 ms 21412 KB Output is correct
15 Correct 55 ms 15912 KB Output is correct
16 Correct 82 ms 19124 KB Output is correct
17 Correct 4 ms 9684 KB Output is correct
18 Correct 5 ms 9684 KB Output is correct
19 Correct 4 ms 9684 KB Output is correct
20 Correct 98 ms 20476 KB Output is correct
21 Correct 4 ms 9684 KB Output is correct
22 Correct 4 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 6 ms 9708 KB Output is correct
3 Correct 4 ms 9708 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 6 ms 9684 KB Output is correct
7 Correct 6 ms 9708 KB Output is correct
8 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 66 ms 16848 KB Output is correct
3 Correct 82 ms 19412 KB Output is correct
4 Correct 114 ms 20928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 66 ms 16848 KB Output is correct
3 Correct 82 ms 19412 KB Output is correct
4 Correct 114 ms 20928 KB Output is correct
5 Partially correct 124 ms 22552 KB Output is partially correct
6 Partially correct 130 ms 22192 KB Output is partially correct
7 Partially correct 127 ms 22200 KB Output is partially correct
8 Partially correct 141 ms 21568 KB Output is partially correct
9 Partially correct 83 ms 16944 KB Output is partially correct
10 Partially correct 132 ms 20796 KB Output is partially correct
11 Partially correct 117 ms 20308 KB Output is partially correct
12 Partially correct 78 ms 16772 KB Output is partially correct
13 Partially correct 86 ms 17952 KB Output is partially correct
14 Partially correct 86 ms 17924 KB Output is partially correct
15 Partially correct 90 ms 18160 KB Output is partially correct
16 Partially correct 7 ms 9980 KB Output is partially correct
17 Partially correct 72 ms 16408 KB Output is partially correct
18 Partially correct 74 ms 16332 KB Output is partially correct
19 Partially correct 72 ms 16372 KB Output is partially correct
20 Partially correct 106 ms 20064 KB Output is partially correct
21 Partially correct 110 ms 19976 KB Output is partially correct
22 Partially correct 105 ms 19660 KB Output is partially correct