Submission #218124

# Submission time Handle Problem Language Result Execution time Memory
218124 2020-04-01T09:42:51 Z dolphingarlic File Paths (BOI15_fil) C++14
100 / 100
297 ms 8184 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=6050;
const int K=2000050;
int par[N],len[N],dep[N],n,m,k,s;
bool ok[N];
vector<int> E[N];
int can[K],cyc[K];
void Add(int u,int f,int p){
	if(u<=n)cyc[dep[u]-dep[p]+s+1]+=f;
	for(int v:E[u])Add(v,f,p);
}
void DFS(int u){
	if(u>n){
		int tmp=k-dep[u];
		if(tmp==0)ok[u]=1;
		for(int i=1;i*i<=tmp;i++)if(tmp%i==0){
			if(cyc[i]||cyc[tmp/i])ok[u]=1;
		}
		for(int v=par[u];v!=-1;v=par[v]){
			if(k-dep[u]+dep[v]-s-1<0)continue;
			if(can[k-dep[u]+dep[v]-s-1])ok[u]=1;
		}
	}else{
		for(int v=u;v!=-1;v=par[v]){
			cyc[dep[u]-dep[v]+s+1]++;
		}
		Add(u,1,u);
	}
	for(int v:E[u])DFS(v);
	if(u<=n){
		for(int v=u;v!=-1;v=par[v]){
			cyc[dep[u]-dep[v]+s+1]--;
		}
		Add(u,-1,u);
	}
}
int main(){
	scanf("%i %i %i %i",&n,&m,&k,&s);
	dep[0]=0;par[0]=-1;can[0]=1;
	for(int i=1;i<=n+m;i++){
		scanf("%i %i",&par[i],&len[i]);
		E[par[i]].pb(i);
		dep[i]=dep[par[i]]+len[i]+1;
		if(i<=n && dep[i]<K)can[dep[i]]++;
	}
	for(int i=0;i<=n;i++)cyc[dep[i]+s+1]++;
	DFS(0);
	for(int i=n+1;i<=n+m;i++)printf("%s\n",ok[i]?"YES":"NO");
	return 0;
}

Compilation message

fil.cpp: In function 'int main()':
fil.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i %i",&n,&m,&k,&s);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fil.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&par[i],&len[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 9 ms 1152 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 3968 KB Output is correct
7 Correct 16 ms 6400 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 9 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7552 KB Output is correct
2 Correct 18 ms 7680 KB Output is correct
3 Correct 17 ms 7552 KB Output is correct
4 Correct 17 ms 7552 KB Output is correct
5 Correct 235 ms 8064 KB Output is correct
6 Correct 246 ms 8184 KB Output is correct
7 Correct 135 ms 7168 KB Output is correct
8 Correct 138 ms 7168 KB Output is correct
9 Correct 19 ms 7168 KB Output is correct
10 Correct 16 ms 7040 KB Output is correct
11 Correct 13 ms 768 KB Output is correct
12 Correct 222 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 9 ms 1152 KB Output is correct
5 Correct 11 ms 5376 KB Output is correct
6 Correct 10 ms 3968 KB Output is correct
7 Correct 16 ms 6400 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 9 ms 1024 KB Output is correct
13 Correct 17 ms 7552 KB Output is correct
14 Correct 18 ms 7680 KB Output is correct
15 Correct 17 ms 7552 KB Output is correct
16 Correct 17 ms 7552 KB Output is correct
17 Correct 235 ms 8064 KB Output is correct
18 Correct 246 ms 8184 KB Output is correct
19 Correct 135 ms 7168 KB Output is correct
20 Correct 138 ms 7168 KB Output is correct
21 Correct 19 ms 7168 KB Output is correct
22 Correct 16 ms 7040 KB Output is correct
23 Correct 13 ms 768 KB Output is correct
24 Correct 222 ms 3456 KB Output is correct
25 Correct 17 ms 7680 KB Output is correct
26 Correct 17 ms 7552 KB Output is correct
27 Correct 17 ms 7552 KB Output is correct
28 Correct 17 ms 7552 KB Output is correct
29 Correct 244 ms 8120 KB Output is correct
30 Correct 265 ms 7976 KB Output is correct
31 Correct 150 ms 7288 KB Output is correct
32 Correct 138 ms 7168 KB Output is correct
33 Correct 16 ms 7168 KB Output is correct
34 Correct 15 ms 7040 KB Output is correct
35 Correct 13 ms 768 KB Output is correct
36 Correct 297 ms 2168 KB Output is correct