답안 #733436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733436 2023-04-30T17:36:21 Z happypotato Snowy Roads (JOI16_snowy) C++17
100 / 100
23 ms 1912 KB
#include "Anyalib.h"

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
 
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 "Borislib.h"

#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
 
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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 656 KB Output is correct
2 Correct 1 ms 780 KB Output is correct
3 Correct 3 ms 832 KB Output is correct
4 Correct 5 ms 1000 KB Output is correct
5 Correct 5 ms 1060 KB Output is correct
6 Correct 7 ms 1044 KB Output is correct
7 Correct 5 ms 1064 KB Output is correct
8 Correct 7 ms 948 KB Output is correct
9 Correct 5 ms 1072 KB Output is correct
10 Correct 6 ms 1056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1228 KB Output is correct
2 Correct 8 ms 1232 KB Output is correct
3 Correct 7 ms 1224 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 11 ms 1228 KB Output is correct
6 Correct 7 ms 1232 KB Output is correct
7 Correct 7 ms 1108 KB Output is correct
8 Correct 7 ms 1228 KB Output is correct
9 Correct 7 ms 1176 KB Output is correct
10 Correct 7 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1704 KB Output is correct
2 Correct 19 ms 1696 KB Output is correct
3 Correct 17 ms 1720 KB Output is correct
4 Correct 17 ms 1684 KB Output is correct
5 Correct 18 ms 1688 KB Output is correct
6 Correct 17 ms 1672 KB Output is correct
7 Correct 17 ms 1668 KB Output is correct
8 Correct 18 ms 1704 KB Output is correct
9 Correct 19 ms 1728 KB Output is correct
10 Correct 17 ms 1688 KB Output is correct
11 Correct 18 ms 1716 KB Output is correct
12 Correct 17 ms 1728 KB Output is correct
13 Correct 20 ms 1712 KB Output is correct
14 Correct 19 ms 1692 KB Output is correct
15 Correct 19 ms 1912 KB Output is correct
16 Correct 19 ms 1688 KB Output is correct
17 Correct 18 ms 1656 KB Output is correct
18 Correct 18 ms 1708 KB Output is correct
19 Correct 19 ms 1668 KB Output is correct
20 Correct 19 ms 1672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1672 KB Output is correct
2 Correct 18 ms 1644 KB Output is correct
3 Correct 17 ms 1604 KB Output is correct
4 Correct 17 ms 1620 KB Output is correct
5 Correct 21 ms 1736 KB Output is correct
6 Correct 17 ms 1676 KB Output is correct
7 Correct 19 ms 1720 KB Output is correct
8 Correct 16 ms 1652 KB Output is correct
9 Correct 18 ms 1668 KB Output is correct
10 Correct 18 ms 1804 KB Output is correct
11 Correct 19 ms 1672 KB Output is correct
12 Correct 18 ms 1580 KB Output is correct
13 Correct 18 ms 1676 KB Output is correct
14 Correct 18 ms 1676 KB Output is correct
15 Correct 18 ms 1672 KB Output is correct
16 Correct 16 ms 1624 KB Output is correct
17 Correct 18 ms 1656 KB Output is correct
18 Correct 19 ms 1584 KB Output is correct
19 Correct 18 ms 1696 KB Output is correct
20 Correct 19 ms 1716 KB Output is correct
21 Correct 23 ms 1696 KB Output is correct
22 Correct 19 ms 1684 KB Output is correct
23 Correct 19 ms 1668 KB Output is correct
24 Correct 18 ms 1696 KB Output is correct
25 Correct 17 ms 1684 KB Output is correct
26 Correct 18 ms 1728 KB Output is correct
27 Correct 18 ms 1680 KB Output is correct
28 Correct 18 ms 1732 KB Output is correct
29 Correct 17 ms 1668 KB Output is correct
30 Correct 17 ms 1712 KB Output is correct
31 Correct 20 ms 1704 KB Output is correct
32 Correct 17 ms 1668 KB Output is correct
33 Correct 19 ms 1756 KB Output is correct
34 Correct 16 ms 1808 KB Output is correct
35 Correct 18 ms 1728 KB Output is correct
36 Correct 19 ms 1708 KB Output is correct
37 Correct 17 ms 1672 KB Output is correct
38 Correct 20 ms 1736 KB Output is correct
39 Correct 16 ms 1424 KB Output is correct
40 Correct 16 ms 1688 KB Output is correct
41 Correct 16 ms 1628 KB Output is correct
42 Correct 16 ms 1680 KB Output is correct
43 Correct 18 ms 1656 KB Output is correct
44 Correct 18 ms 1736 KB Output is correct
45 Correct 19 ms 1672 KB Output is correct
46 Correct 17 ms 1424 KB Output is correct
47 Correct 19 ms 1396 KB Output is correct
48 Correct 18 ms 1316 KB Output is correct
49 Correct 16 ms 1108 KB Output is correct
50 Correct 17 ms 1072 KB Output is correct