답안 #883329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883329 2023-12-05T07:30:22 Z serifefedartar Regions (IOI09_regions) C++17
5 / 100
7 ms 10200 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9 + 9;
const ll LOGN = 21;
const ll MAXN = 505;

vector<vector<int>> graph;
int reg[MAXN], dp[505][505];
vector<int> cnt[MAXN];
void dfs(int node, int parent) {
	cnt[node][reg[node]]++;
	for (int reg_other = 1; reg_other <= 500; reg_other++)
		dp[reg_other][reg[node]] += cnt[node][reg_other];
	for (auto u : graph[node]) {
		swap(cnt[u], cnt[node]);
		dfs(u, node);
	}
	cnt[node][reg[node]]--;
	swap(cnt[parent], cnt[node]);
}

int main() {
	fast
	int N, R, Q, a, b;
	cin >> N >> R >> Q;

	graph = vector<vector<int>>(N+1, vector<int>());
	cin >> reg[1];
	for (int i = 2; i <= N; i++) {
		int S;
		cin >> S >> reg[i];
		graph[S].push_back(i);
	}

	if (R <= 500) {
		cnt[1] = vector<int>(505, 0);
		dfs(1, 1);
		for (int i = 0; i < Q; i++) {
			cin >> a >> b;
			cout << dp[a][b] << endl;
		}
	} else {
		// 
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1368 KB Output is correct
4 Correct 2 ms 1368 KB Output is correct
5 Correct 3 ms 1368 KB Output is correct
6 Runtime error 1 ms 600 KB Execution killed with signal 11
7 Runtime error 1 ms 600 KB Execution killed with signal 11
8 Runtime error 1 ms 600 KB Execution killed with signal 11
9 Runtime error 1 ms 856 KB Execution killed with signal 11
10 Runtime error 1 ms 1112 KB Execution killed with signal 11
11 Runtime error 1 ms 1368 KB Execution killed with signal 11
12 Runtime error 1 ms 1624 KB Execution killed with signal 11
13 Runtime error 1 ms 1620 KB Execution killed with signal 11
14 Runtime error 1 ms 1880 KB Execution killed with signal 11
15 Runtime error 2 ms 2392 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 4184 KB Execution killed with signal 11
2 Runtime error 3 ms 4440 KB Execution killed with signal 11
3 Runtime error 3 ms 4952 KB Execution killed with signal 11
4 Runtime error 2 ms 1880 KB Execution killed with signal 11
5 Runtime error 2 ms 2392 KB Execution killed with signal 11
6 Runtime error 2 ms 2904 KB Execution killed with signal 11
7 Runtime error 3 ms 3804 KB Execution killed with signal 11
8 Runtime error 4 ms 5208 KB Execution killed with signal 11
9 Runtime error 4 ms 7768 KB Execution killed with signal 11
10 Runtime error 7 ms 8792 KB Execution killed with signal 11
11 Runtime error 6 ms 10072 KB Execution killed with signal 11
12 Runtime error 5 ms 9556 KB Execution killed with signal 11
13 Runtime error 5 ms 9560 KB Execution killed with signal 11
14 Runtime error 5 ms 10072 KB Execution killed with signal 11
15 Runtime error 5 ms 10072 KB Execution killed with signal 11
16 Runtime error 6 ms 10200 KB Execution killed with signal 11
17 Runtime error 5 ms 10072 KB Execution killed with signal 11