# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
953156 |
2024-03-25T15:00:21 Z |
PM1 |
File Paths (BOI15_fil) |
C++17 |
|
120 ms |
4828 KB |
#include <bits/stdc++.h>
using namespace std;
const int mxn=3e3+5,mxs=1e6+5;
int n,m,s,k,par[mxn*2],dis[mxn*2];
vector<int>all,v[mxn*2];
int mark[mxs],ans[mxn*2];
void make(int x,bool y){
int z=x;
while(x!=0){
x=par[x];
int d=dis[z]-dis[x];
if(d<=k)mark[d]=y;
}
}
void dfs1(int z,int g,int x){
if(z>n)
return ;
int y=x+dis[z];
if(y<mxs)
mark[y]+=g;
for(auto i:v[z])
dfs1(i,g,x);
}
void dfs(int z){
if(z>n){
int x=k-dis[z];
for(int i=1;i*i<=x;i++){
if(x%i==0 &&(mark[i] || mark[x/i]))ans[z]=1;
}
}
dfs1(z,1,s-dis[z]);
for(auto i:v[z])
dfs(i);
dfs1(z,-1,s-dis[z]);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k>>s;
s++;
dis[0]=1;
for(int i=1;i<=n+m;i++){
int x,y;
cin>>x>>y;
par[i]=x;
dis[i]=dis[x]+y;
v[x].push_back(i);
if(i<=n){
dis[i]++;
all.push_back(dis[i]);
}
}
all.push_back(1);
for(int i=n+1;i<=n+m;i++){
make(i,1);
if(dis[i]==k)ans[i]=1;
for(auto j:all){
int res=k-j-s;
if(res>=0 && mark[res])ans[i]=1;
}
make(i,0);
}
dfs(0);
for(int i=n+1;i<=n+m;i++){
if(ans[i])
cout<<"YES"<<'\n';
else
cout<<"NO"<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2648 KB |
Output is correct |
5 |
Correct |
4 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
3160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4444 KB |
Output is correct |
2 |
Correct |
18 ms |
4440 KB |
Output is correct |
3 |
Correct |
17 ms |
4440 KB |
Output is correct |
4 |
Correct |
20 ms |
4676 KB |
Output is correct |
5 |
Correct |
103 ms |
4680 KB |
Output is correct |
6 |
Correct |
102 ms |
4772 KB |
Output is correct |
7 |
Correct |
74 ms |
4712 KB |
Output is correct |
8 |
Correct |
65 ms |
4696 KB |
Output is correct |
9 |
Correct |
18 ms |
4440 KB |
Output is correct |
10 |
Correct |
17 ms |
4444 KB |
Output is correct |
11 |
Correct |
11 ms |
856 KB |
Output is correct |
12 |
Correct |
96 ms |
4380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
3 ms |
2648 KB |
Output is correct |
5 |
Correct |
4 ms |
4444 KB |
Output is correct |
6 |
Correct |
4 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4444 KB |
Output is correct |
8 |
Correct |
3 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
4440 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
3160 KB |
Output is correct |
13 |
Correct |
20 ms |
4444 KB |
Output is correct |
14 |
Correct |
18 ms |
4440 KB |
Output is correct |
15 |
Correct |
17 ms |
4440 KB |
Output is correct |
16 |
Correct |
20 ms |
4676 KB |
Output is correct |
17 |
Correct |
103 ms |
4680 KB |
Output is correct |
18 |
Correct |
102 ms |
4772 KB |
Output is correct |
19 |
Correct |
74 ms |
4712 KB |
Output is correct |
20 |
Correct |
65 ms |
4696 KB |
Output is correct |
21 |
Correct |
18 ms |
4440 KB |
Output is correct |
22 |
Correct |
17 ms |
4444 KB |
Output is correct |
23 |
Correct |
11 ms |
856 KB |
Output is correct |
24 |
Correct |
96 ms |
4380 KB |
Output is correct |
25 |
Correct |
19 ms |
4700 KB |
Output is correct |
26 |
Correct |
18 ms |
4696 KB |
Output is correct |
27 |
Correct |
17 ms |
4700 KB |
Output is correct |
28 |
Correct |
17 ms |
4604 KB |
Output is correct |
29 |
Correct |
102 ms |
4828 KB |
Output is correct |
30 |
Correct |
110 ms |
4740 KB |
Output is correct |
31 |
Correct |
66 ms |
4696 KB |
Output is correct |
32 |
Correct |
86 ms |
4700 KB |
Output is correct |
33 |
Correct |
16 ms |
4696 KB |
Output is correct |
34 |
Correct |
16 ms |
4696 KB |
Output is correct |
35 |
Correct |
12 ms |
872 KB |
Output is correct |
36 |
Correct |
120 ms |
3736 KB |
Output is correct |