Submission #198301

# Submission time Handle Problem Language Result Execution time Memory
198301 2020-01-25T13:11:56 Z dndhk File Paths (BOI15_fil) C++14
100 / 100
208 ms 26028 KB
#include <bits/stdc++.h>

#define all(v) (v).begin(), (v).end()
#define sort(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 6000;
const int MAX_K = 1000000;

int N, M, K, S;
int p[MAX_N+1], c[MAX_N+1];

vector<int> gp[MAX_N+1];
vector<int> vt[MAX_N+1];
bool chk[MAX_K+1];
int chk2[MAX_K+1];
bool ans[MAX_N+1];
int sum[MAX_N+1];

void dfs(int x){
	if(x!=0)sum[x] = sum[p[x]] + c[x] + 1;
	if(x<=N)	chk[sum[x]] = true;
	int t = p[x];
	while(x<=N){
		if(sum[x] - sum[t] + S + 1 <= K)	vt[t].pb(sum[x]-sum[t]+S+1);
		if(t==0)	break;
		t = p[t];
	}
	for(int i : gp[x]){
		dfs(i);
	}
}

void dfs2(int x){
	for(int t : vt[x]){
		chk2[t]++;
	}
	if(x>N){
		if(sum[x]==K){
			ans[x] = true;
		}else if(sum[x]<K){
			int t = p[x];
			while(1){
				int n = K-(sum[x]-sum[t]+S+1);
				if(n>=0 && n<=K){
					if(chk[n]){
						ans[x] = true;
						break;
					}
				}
				if(t==0)	break;
				t = p[t];
			}
			if(!ans[x]){
				int n = K - sum[x];
				for(int j=2; j*j<=n; j++){
					if(n%j==0){
						if(chk2[j]>0){
							ans[x] = true;
							break;
						}
						if(chk2[n/j]>0){
							ans[x] = true;
							break;
						}
					}
				}
			}
		}else{
			int t = p[x];
			while(1){
				int n = K - (sum[x]-sum[t]+S+1);
				if(n>=0 && n<=K){
					if(chk[n]){
						ans[x] = true;
						break;
					}
				}
				if(t==0)	break;
				t = p[t];
			}
		}
	}
	for(int i : gp[x]){
		dfs2(i);
	}
	for(int t : vt[x]){
		chk2[t]--;
	}
}

int main(){
	scanf("%d%d%d", &N, &M, &K);
	scanf("%d", &S);
	vt[0].pb(S+1);
	for(int i=1; i<=N; i++){
		scanf("%d%d", &p[i], &c[i]);
		gp[p[i]].pb(i);
	}
	for(int i=N+1; i<=N+M; i++){
		scanf("%d%d", &p[i], &c[i]);
		gp[p[i]].pb(i);
	}
	dfs(0);
	// for(int i=1; i<=N; i++){
	// 	printf("%d %d\n", i, sum[i]);
	// }
	dfs2(0);
	for(int i=N+1; i<=N+M; i++){
		if(ans[i]){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

Compilation message

fil.cpp: In function 'int main()':
fil.cpp:111:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &M, &K);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fil.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &S);
  ~~~~~^~~~~~~~~~
fil.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &p[i], &c[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fil.cpp:119:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &p[i], &c[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 5 ms 1528 KB Output is correct
5 Correct 7 ms 4984 KB Output is correct
6 Correct 6 ms 3448 KB Output is correct
7 Correct 10 ms 5368 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 6 ms 4600 KB Output is correct
10 Correct 1 ms 632 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 5 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 5368 KB Output is correct
2 Correct 11 ms 5372 KB Output is correct
3 Correct 11 ms 5624 KB Output is correct
4 Correct 11 ms 5624 KB Output is correct
5 Correct 162 ms 25252 KB Output is correct
6 Correct 154 ms 25592 KB Output is correct
7 Correct 78 ms 16168 KB Output is correct
8 Correct 81 ms 16468 KB Output is correct
9 Correct 12 ms 5112 KB Output is correct
10 Correct 11 ms 4472 KB Output is correct
11 Correct 8 ms 1528 KB Output is correct
12 Correct 151 ms 21796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 5 ms 1528 KB Output is correct
5 Correct 7 ms 4984 KB Output is correct
6 Correct 6 ms 3448 KB Output is correct
7 Correct 10 ms 5368 KB Output is correct
8 Correct 6 ms 4472 KB Output is correct
9 Correct 6 ms 4600 KB Output is correct
10 Correct 1 ms 632 KB Output is correct
11 Correct 3 ms 760 KB Output is correct
12 Correct 5 ms 1528 KB Output is correct
13 Correct 11 ms 5368 KB Output is correct
14 Correct 11 ms 5372 KB Output is correct
15 Correct 11 ms 5624 KB Output is correct
16 Correct 11 ms 5624 KB Output is correct
17 Correct 162 ms 25252 KB Output is correct
18 Correct 154 ms 25592 KB Output is correct
19 Correct 78 ms 16168 KB Output is correct
20 Correct 81 ms 16468 KB Output is correct
21 Correct 12 ms 5112 KB Output is correct
22 Correct 11 ms 4472 KB Output is correct
23 Correct 8 ms 1528 KB Output is correct
24 Correct 151 ms 21796 KB Output is correct
25 Correct 11 ms 5368 KB Output is correct
26 Correct 10 ms 5368 KB Output is correct
27 Correct 11 ms 5380 KB Output is correct
28 Correct 11 ms 5624 KB Output is correct
29 Correct 178 ms 25348 KB Output is correct
30 Correct 161 ms 25196 KB Output is correct
31 Correct 77 ms 16376 KB Output is correct
32 Correct 77 ms 15992 KB Output is correct
33 Correct 10 ms 4472 KB Output is correct
34 Correct 10 ms 4600 KB Output is correct
35 Correct 8 ms 1400 KB Output is correct
36 Correct 208 ms 26028 KB Output is correct