# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
310064 |
2020-10-05T12:40:29 Z |
soroush |
File Paths (BOI15_fil) |
C++14 |
|
305 ms |
62196 KB |
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int ,int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 2e6+1000;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n , m , k;
int ans[maxn];
int s;
int dist[maxn];
vector < int > adj[maxn] , pval;
int cnt[maxn];
int cont[maxn];
void dfs2(int v,int val, bool f = 0){
if(v > n)return;
cont[dist[v] + val] += ((f) ? -1 : 1);
for(auto u : adj[v])
dfs2(u ,val ,f);
}
void dfs(int v = 0){
if(v <= n){
pval.pb(dist[v]);
dfs2(v , s - dist[v]);
for(auto u : adj[v])
dfs(u);
dfs2(v , s - dist[v] , 1);
pval.pop_back();
return;
}
for(auto x : pval)
if(k - (dist[v] - x) - s >= 0 and cnt[k - (dist[v] - x) - s ])
ans[v - n] = 1;
int rmn = k - dist[v];
if(rmn <= 0)
return;
for(int i = 1 ; i * i <= rmn ; i ++){
if(rmn%i == 0 and cont[i] ){
ans[v - n] = 1;
return;
}
if(rmn%(rmn/ i) == 0 and cont[rmn / i]){
ans[v - n] = 1;
return;
}
}
}
int32_t main(){
migmig
cin >> n >> m >> k;
cin >> s;
s++;
dist[0] = 1;
for(int i = 1 ; i <= n ; i ++){
int p;
cin >> p >> dist[i];
dist[i] ++ ;
dist[i] += dist[p];
adj[p].pb(i);
}
for(int i = 0 ; i <= n ; i ++) cnt[dist[i]] ++;
for(int i = n+1; i <= n + m ; i ++){
int p;
cin >> p >> dist[i];
dist[i] += dist[p];
if(dist[i] == k) ans[i - n] = 1;
else adj[p].pb(i);
}
dfs();
for(int i = 1 ; i <= m ; i ++)
cout << ((ans[i])?"YES" : "NO") << endl;
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47360 KB |
Output is correct |
2 |
Correct |
32 ms |
47480 KB |
Output is correct |
3 |
Correct |
34 ms |
48768 KB |
Output is correct |
4 |
Correct |
35 ms |
48888 KB |
Output is correct |
5 |
Correct |
41 ms |
55928 KB |
Output is correct |
6 |
Correct |
39 ms |
51896 KB |
Output is correct |
7 |
Correct |
46 ms |
57208 KB |
Output is correct |
8 |
Correct |
37 ms |
53888 KB |
Output is correct |
9 |
Correct |
38 ms |
54016 KB |
Output is correct |
10 |
Correct |
31 ms |
47360 KB |
Output is correct |
11 |
Correct |
33 ms |
47360 KB |
Output is correct |
12 |
Correct |
37 ms |
48512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
59512 KB |
Output is correct |
2 |
Correct |
51 ms |
59656 KB |
Output is correct |
3 |
Correct |
51 ms |
59384 KB |
Output is correct |
4 |
Correct |
52 ms |
59768 KB |
Output is correct |
5 |
Correct |
296 ms |
61944 KB |
Output is correct |
6 |
Correct |
297 ms |
61908 KB |
Output is correct |
7 |
Correct |
174 ms |
59640 KB |
Output is correct |
8 |
Correct |
173 ms |
59640 KB |
Output is correct |
9 |
Correct |
55 ms |
59516 KB |
Output is correct |
10 |
Correct |
51 ms |
59000 KB |
Output is correct |
11 |
Correct |
38 ms |
47744 KB |
Output is correct |
12 |
Correct |
197 ms |
53004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
47360 KB |
Output is correct |
2 |
Correct |
32 ms |
47480 KB |
Output is correct |
3 |
Correct |
34 ms |
48768 KB |
Output is correct |
4 |
Correct |
35 ms |
48888 KB |
Output is correct |
5 |
Correct |
41 ms |
55928 KB |
Output is correct |
6 |
Correct |
39 ms |
51896 KB |
Output is correct |
7 |
Correct |
46 ms |
57208 KB |
Output is correct |
8 |
Correct |
37 ms |
53888 KB |
Output is correct |
9 |
Correct |
38 ms |
54016 KB |
Output is correct |
10 |
Correct |
31 ms |
47360 KB |
Output is correct |
11 |
Correct |
33 ms |
47360 KB |
Output is correct |
12 |
Correct |
37 ms |
48512 KB |
Output is correct |
13 |
Correct |
50 ms |
59512 KB |
Output is correct |
14 |
Correct |
51 ms |
59656 KB |
Output is correct |
15 |
Correct |
51 ms |
59384 KB |
Output is correct |
16 |
Correct |
52 ms |
59768 KB |
Output is correct |
17 |
Correct |
296 ms |
61944 KB |
Output is correct |
18 |
Correct |
297 ms |
61908 KB |
Output is correct |
19 |
Correct |
174 ms |
59640 KB |
Output is correct |
20 |
Correct |
173 ms |
59640 KB |
Output is correct |
21 |
Correct |
55 ms |
59516 KB |
Output is correct |
22 |
Correct |
51 ms |
59000 KB |
Output is correct |
23 |
Correct |
38 ms |
47744 KB |
Output is correct |
24 |
Correct |
197 ms |
53004 KB |
Output is correct |
25 |
Correct |
48 ms |
59748 KB |
Output is correct |
26 |
Correct |
48 ms |
59384 KB |
Output is correct |
27 |
Correct |
50 ms |
59392 KB |
Output is correct |
28 |
Correct |
48 ms |
59384 KB |
Output is correct |
29 |
Correct |
283 ms |
62196 KB |
Output is correct |
30 |
Correct |
305 ms |
62084 KB |
Output is correct |
31 |
Correct |
175 ms |
59512 KB |
Output is correct |
32 |
Correct |
185 ms |
59640 KB |
Output is correct |
33 |
Correct |
50 ms |
59384 KB |
Output is correct |
34 |
Correct |
47 ms |
59048 KB |
Output is correct |
35 |
Correct |
38 ms |
47616 KB |
Output is correct |
36 |
Correct |
235 ms |
50296 KB |
Output is correct |