답안 #250251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250251 2020-07-17T10:15:51 Z tutis File Paths (BOI15_fil) C++17
33 / 100
1000 ms 20472 KB
/*input
2 4 22
2
0 1
1 5
2 13
2 10
1 4
0 7

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0), cerr.tie(0);
	int n, m, k, s;
	cin >> n >> m >> k >> s;
	s++;
	int p[n + 1], d[n + 1], l[n + 1];
	p[0] = -1;
	d[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i] >> l[i];
		d[i] = d[p[i]] + 1 + l[i];
	}
	vector<int>cikl[n + 1];
	for (int i = 0; i <= n; i++)
	{
		for (int j = i; j != -1; j = p[j])
		{
			cikl[j].push_back(d[i] - d[j] + s);
		}
	}
	function<bool(int, int)>ok = [&](int v, int ilg)
	{
		if (d[v] == ilg)
			return true;
		if (ilg <= 0)
			return false;
		if (v != 0 && ok(p[v], ilg - 1 - l[v]))
			return true;
		for (int w = 0; w <= n; w++)
		{
			//w->v
			if (d[w] + s == ilg)
				return true;
		}
		if (ilg <= d[v])
			return false;
		for (int x : cikl[v])
		{
			if ((ilg - d[v]) % x == 0)
				return true;
		}
		return false;
	};
	while (m--)
	{
		int p, l;
		cin >> p >> l;
		if (ok(p, k - l))
			cout << "YES\n";
		else
			cout << "NO\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 81 ms 808 KB Output is correct
5 Correct 12 ms 524 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 145 ms 1040 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 57 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 672 KB Output is correct
2 Correct 46 ms 640 KB Output is correct
3 Correct 46 ms 640 KB Output is correct
4 Correct 49 ms 640 KB Output is correct
5 Execution timed out 1094 ms 20472 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 81 ms 808 KB Output is correct
5 Correct 12 ms 524 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 145 ms 1040 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 57 ms 868 KB Output is correct
13 Correct 50 ms 672 KB Output is correct
14 Correct 46 ms 640 KB Output is correct
15 Correct 46 ms 640 KB Output is correct
16 Correct 49 ms 640 KB Output is correct
17 Execution timed out 1094 ms 20472 KB Time limit exceeded
18 Halted 0 ms 0 KB -