답안 #302802

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
302802 2020-09-19T08:38:06 Z BlancaHM Regions (IOI09_regions) C++14
14 / 100
8000 ms 21600 KB
#include <iostream>
#include <fstream>
#include <cfloat>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<string> vs;
#define fir first
#define sec second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()

vi country;
vvi G;
int N, R, e1, e2, ans;

int dfs(int S) {
	int cur = 0;
	for (auto v: G[S]) {
		cur += dfs(v);
		if (country[v] == e2) cur++;
	}
	if (country[S] == e1) ans += cur;
	return cur;
}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(NULL);
	int Q, cn, sup;
	cin >> N >> R >> Q;
	G.assign(N, vi());
	country = vi(N);
	cin >> cn;
	country[0] = cn;
	map<pii, int> past;
	for (int i = 1; i < N; i++) {
		cin >> sup >> cn;
		G[sup-1].push_back(i);
		country[i] = cn;
	}
	while(Q--) {
		cin >> e1 >> e2;
		if (past.find(mp(e1, e2)) != past.end()) {
			cout << past[mp(e1, e2)] << "\n";
			continue;
		}
		ans = 0;
		dfs(0);
		cout << ans << "\n";
		past[mp(e1, e2)] = ans;
		cout.flush();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 7 ms 384 KB Output is correct
5 Correct 8 ms 408 KB Output is correct
6 Correct 36 ms 504 KB Output is correct
7 Correct 89 ms 504 KB Output is correct
8 Correct 136 ms 632 KB Output is correct
9 Correct 265 ms 1272 KB Output is correct
10 Correct 1742 ms 1540 KB Output is correct
11 Correct 3391 ms 2224 KB Output is correct
12 Correct 3586 ms 2612 KB Output is correct
13 Correct 7662 ms 2644 KB Output is correct
14 Execution timed out 8007 ms 2880 KB Time limit exceeded
15 Correct 6288 ms 5988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 8006 ms 6292 KB Time limit exceeded
2 Execution timed out 8073 ms 4800 KB Time limit exceeded
3 Execution timed out 8055 ms 8100 KB Time limit exceeded
4 Execution timed out 8096 ms 2956 KB Time limit exceeded
5 Execution timed out 8063 ms 5432 KB Time limit exceeded
6 Execution timed out 8007 ms 4132 KB Time limit exceeded
7 Execution timed out 8055 ms 4940 KB Time limit exceeded
8 Execution timed out 8066 ms 10340 KB Time limit exceeded
9 Execution timed out 8099 ms 10104 KB Time limit exceeded
10 Execution timed out 8034 ms 14820 KB Time limit exceeded
11 Execution timed out 8084 ms 9980 KB Time limit exceeded
12 Execution timed out 8074 ms 11768 KB Time limit exceeded
13 Execution timed out 8071 ms 11836 KB Time limit exceeded
14 Execution timed out 8036 ms 11824 KB Time limit exceeded
15 Execution timed out 8063 ms 16016 KB Time limit exceeded
16 Execution timed out 8066 ms 21600 KB Time limit exceeded
17 Execution timed out 8029 ms 20216 KB Time limit exceeded