Submission #733433

# Submission time Handle Problem Language Result Execution time Memory
733433 2023-04-30T17:25:52 Z happypotato None (JOI16_snowy) C++17
100 / 100
24 ms 1924 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back

void Save(int place, int bit);

const int mxN = 1000;
int n;
vector<pii> edge;
 
vector<pair<int, pii>> adj[mxN]; // {node, {0/1, idx}}
int ans[mxN];
vector<int> key;
map<int, int> mp;
pii par[mxN];
int dfs(int u = 0, int pp = -1, int cur = 0) {
	ans[u] = cur;
	int res = 0;
	for (pair<int, pii> &v : adj[u]) {
		if (v.ff == pp) continue;
		par[v.ff] = {u, v.ss.ss};
		res = max(res, dfs(v.ff, u, cur + v.ss.ff) + 1);
	}
	if (res >= 10) {
		key.pb(u);
		res -= 10;
	}
	return res;
}
 
void InitAnya(int N, int A[], int B[]) {
	n = N;
	for (int i = 0; i < n - 1; i++) {
		edge.pb({A[i], B[i]});
	}
}
 
void Anya(int C[]) {
	for (int i = 0; i < n; i++) {
		adj[i].clear();
	}
	key.clear();
	for (int i = 0; i < n - 1; i++) {
		adj[edge[i].ff].pb({edge[i].ss, {C[i], i}});
		adj[edge[i].ss].pb({edge[i].ff, {C[i], i}});
	}
	dfs();
	for (int i = 0; i < n - 1; i++) {
		Save(500 + i, C[i]);
	}
	assert(key.size() <= 50);
	for (int i = 0; i < (int)(key.size()); i++) {
		for (int j = 0; j < 10; j++) {
			Save(i * 10 + j, bool(ans[key[i]] & (1 << j)));
		}
	}
}
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back

int Ask(int place);

const int mxN = 1000;
int n;
vector<pii> edge;
 
vector<pair<int, pii>> adj[mxN]; // {node, {0/1, idx}}
int ans[mxN];
vector<int> key;
map<int, int> mp;
pii par[mxN];
int dfs(int u = 0, int pp = -1, int cur = 0) {
	ans[u] = cur;
	int res = 0;
	for (pair<int, pii> &v : adj[u]) {
		if (v.ff == pp) continue;
		par[v.ff] = {u, v.ss.ss};
		res = max(res, dfs(v.ff, u, cur + v.ss.ff) + 1);
	}
	if (res >= 10) {
		key.pb(u);
		res -= 10;
	}
	return res;
}
 
void InitBoris(int N, int A[], int B[]) {
	n = N;
	for (int i = 0; i < n - 1; i++) {
		adj[A[i]].pb({B[i], {0, i}});
		adj[B[i]].pb({A[i], {0, i}});
	}
	dfs();
	mp[0] = -1;
	for (int i = 0; i < (int)(key.size()); i++) {
		mp[key[i]] = i;
	}
}
 
int Boris(int city) {
	int ans = 0;
	while (mp.find(city) == mp.end()) {
		ans += Ask(500 + par[city].ss);
		city = par[city].ff;
	}
	if (city) {
		for (int i = 0; i < 10; i++) {
			ans += (Ask(mp[city] * 10 + i) << i);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 772 KB Output is correct
2 Correct 2 ms 780 KB Output is correct
3 Correct 3 ms 836 KB Output is correct
4 Correct 4 ms 872 KB Output is correct
5 Correct 5 ms 1056 KB Output is correct
6 Correct 7 ms 928 KB Output is correct
7 Correct 5 ms 1128 KB Output is correct
8 Correct 7 ms 1180 KB Output is correct
9 Correct 6 ms 936 KB Output is correct
10 Correct 5 ms 1064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1224 KB Output is correct
2 Correct 7 ms 1228 KB Output is correct
3 Correct 8 ms 1240 KB Output is correct
4 Correct 8 ms 1228 KB Output is correct
5 Correct 7 ms 1232 KB Output is correct
6 Correct 9 ms 1248 KB Output is correct
7 Correct 7 ms 1236 KB Output is correct
8 Correct 8 ms 1228 KB Output is correct
9 Correct 8 ms 1232 KB Output is correct
10 Correct 7 ms 1188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1612 KB Output is correct
2 Correct 20 ms 1728 KB Output is correct
3 Correct 19 ms 1684 KB Output is correct
4 Correct 19 ms 1672 KB Output is correct
5 Correct 20 ms 1688 KB Output is correct
6 Correct 20 ms 1768 KB Output is correct
7 Correct 20 ms 1760 KB Output is correct
8 Correct 17 ms 1708 KB Output is correct
9 Correct 19 ms 1668 KB Output is correct
10 Correct 20 ms 1696 KB Output is correct
11 Correct 18 ms 1692 KB Output is correct
12 Correct 19 ms 1756 KB Output is correct
13 Correct 19 ms 1636 KB Output is correct
14 Correct 20 ms 1664 KB Output is correct
15 Correct 20 ms 1640 KB Output is correct
16 Correct 19 ms 1624 KB Output is correct
17 Correct 17 ms 1688 KB Output is correct
18 Correct 17 ms 1716 KB Output is correct
19 Correct 18 ms 1676 KB Output is correct
20 Correct 19 ms 1708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1620 KB Output is correct
2 Correct 20 ms 1692 KB Output is correct
3 Correct 16 ms 1604 KB Output is correct
4 Correct 19 ms 1704 KB Output is correct
5 Correct 19 ms 1660 KB Output is correct
6 Correct 18 ms 1668 KB Output is correct
7 Correct 19 ms 1864 KB Output is correct
8 Correct 17 ms 1696 KB Output is correct
9 Correct 20 ms 1712 KB Output is correct
10 Correct 18 ms 1516 KB Output is correct
11 Correct 19 ms 1748 KB Output is correct
12 Correct 18 ms 1668 KB Output is correct
13 Correct 20 ms 1688 KB Output is correct
14 Correct 19 ms 1700 KB Output is correct
15 Correct 19 ms 1680 KB Output is correct
16 Correct 17 ms 1580 KB Output is correct
17 Correct 20 ms 1684 KB Output is correct
18 Correct 19 ms 1684 KB Output is correct
19 Correct 19 ms 1644 KB Output is correct
20 Correct 19 ms 1696 KB Output is correct
21 Correct 19 ms 1656 KB Output is correct
22 Correct 18 ms 1684 KB Output is correct
23 Correct 19 ms 1820 KB Output is correct
24 Correct 17 ms 1700 KB Output is correct
25 Correct 18 ms 1708 KB Output is correct
26 Correct 18 ms 1616 KB Output is correct
27 Correct 18 ms 1652 KB Output is correct
28 Correct 18 ms 1644 KB Output is correct
29 Correct 24 ms 1628 KB Output is correct
30 Correct 19 ms 1672 KB Output is correct
31 Correct 20 ms 1688 KB Output is correct
32 Correct 18 ms 1680 KB Output is correct
33 Correct 19 ms 1656 KB Output is correct
34 Correct 20 ms 1680 KB Output is correct
35 Correct 16 ms 1740 KB Output is correct
36 Correct 20 ms 1688 KB Output is correct
37 Correct 17 ms 1748 KB Output is correct
38 Correct 22 ms 1712 KB Output is correct
39 Correct 18 ms 1612 KB Output is correct
40 Correct 17 ms 1704 KB Output is correct
41 Correct 17 ms 1924 KB Output is correct
42 Correct 17 ms 1676 KB Output is correct
43 Correct 17 ms 1708 KB Output is correct
44 Correct 19 ms 1672 KB Output is correct
45 Correct 19 ms 1628 KB Output is correct
46 Correct 18 ms 1592 KB Output is correct
47 Correct 17 ms 1684 KB Output is correct
48 Correct 18 ms 1724 KB Output is correct
49 Correct 18 ms 1696 KB Output is correct
50 Correct 18 ms 1692 KB Output is correct