답안 #200608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200608 2020-02-07T14:51:51 Z TadijaSebez File Paths (BOI15_fil) C++11
100 / 100
305 ms 8252 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]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 6 ms 1272 KB Output is correct
4 Correct 10 ms 1272 KB Output is correct
5 Correct 12 ms 5368 KB Output is correct
6 Correct 11 ms 3960 KB Output is correct
7 Correct 18 ms 6392 KB Output is correct
8 Correct 9 ms 5112 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 10 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 7676 KB Output is correct
2 Correct 20 ms 7600 KB Output is correct
3 Correct 19 ms 7672 KB Output is correct
4 Correct 19 ms 7544 KB Output is correct
5 Correct 278 ms 8056 KB Output is correct
6 Correct 270 ms 8056 KB Output is correct
7 Correct 157 ms 7160 KB Output is correct
8 Correct 170 ms 7216 KB Output is correct
9 Correct 21 ms 7256 KB Output is correct
10 Correct 19 ms 7160 KB Output is correct
11 Correct 15 ms 764 KB Output is correct
12 Correct 236 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 6 ms 1272 KB Output is correct
4 Correct 10 ms 1272 KB Output is correct
5 Correct 12 ms 5368 KB Output is correct
6 Correct 11 ms 3960 KB Output is correct
7 Correct 18 ms 6392 KB Output is correct
8 Correct 9 ms 5112 KB Output is correct
9 Correct 9 ms 5240 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 10 ms 1144 KB Output is correct
13 Correct 19 ms 7676 KB Output is correct
14 Correct 20 ms 7600 KB Output is correct
15 Correct 19 ms 7672 KB Output is correct
16 Correct 19 ms 7544 KB Output is correct
17 Correct 278 ms 8056 KB Output is correct
18 Correct 270 ms 8056 KB Output is correct
19 Correct 157 ms 7160 KB Output is correct
20 Correct 170 ms 7216 KB Output is correct
21 Correct 21 ms 7256 KB Output is correct
22 Correct 19 ms 7160 KB Output is correct
23 Correct 15 ms 764 KB Output is correct
24 Correct 236 ms 3448 KB Output is correct
25 Correct 18 ms 7672 KB Output is correct
26 Correct 22 ms 7596 KB Output is correct
27 Correct 18 ms 7544 KB Output is correct
28 Correct 22 ms 7544 KB Output is correct
29 Correct 301 ms 8252 KB Output is correct
30 Correct 296 ms 8164 KB Output is correct
31 Correct 172 ms 7192 KB Output is correct
32 Correct 174 ms 7288 KB Output is correct
33 Correct 19 ms 7160 KB Output is correct
34 Correct 17 ms 7160 KB Output is correct
35 Correct 13 ms 888 KB Output is correct
36 Correct 305 ms 2096 KB Output is correct