# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260714 | 2020-08-10T19:04:17 Z | fadi57 | Long Mansion (JOI17_long_mansion) | C++14 | 445 ms | 52472 KB |
/* - Find the closest key that unlocks the door to the left and to the right for every door. - For every room expand the interval that we can get to from that room based on if we can find the key to the door to the left or to the right in the current interval we can reach from that room. */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define pb push_back using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; ///find_by_order(),order_of_key() const int N=5*1e5+5; vector<int> hi(N),lo(N),l(N),r(N); bool on(int l,int r,int x){return x>=l&&x<=r;} bool can(int l,int r,int x){return (hi[x]>=0&&on(l,r,hi[x]))||(lo[x]>=0&&on(l,r,lo[x]));} int main() { int n; scanf("%i",&n); vector<int> cor(n-1); for(int i=0;i<n-1;i++) scanf("%i",&cor[i]); vector<vector<int> > sobe(n); for(int i=0;i<n;i++) { int b; scanf("%i",&b); for(int j=0;j<b;j++) { int a; scanf("%i",&a); sobe[i].pb(a); } } vector<int> keys(n,-1); for(int i=0;i<n-1;i++) { for(auto p:sobe[i]) keys[p]=i; lo[i]=keys[cor[i]]; } fill(keys.begin(),keys.end(),-1); for(int i=n-1;i>0;i--) { for(auto p:sobe[i]) keys[p]=i; hi[i-1]=keys[cor[i-1]]; } for(int i=0;i<n;i++) { l[i]=r[i]=i; while(true) { if(l[i]>0&&can(l[i],r[i],l[i]-1)) { r[i]=max(r[i],r[l[i]-1]); l[i]=l[l[i]-1]; } else if(r[i]<n-1&&can(l[i],r[i],r[i])) r[i]++; else break; } } int q; scanf("%i",&q); for(int i=0;i<q;i++) { int x,y; scanf("%i %i",&x,&y); x--; y--; if(on(l[x],r[x],y)) printf("YES\n"); else printf("NO\n"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8320 KB | Output is correct |
2 | Correct | 9 ms | 8448 KB | Output is correct |
3 | Correct | 11 ms | 8576 KB | Output is correct |
4 | Correct | 8 ms | 8320 KB | Output is correct |
5 | Correct | 8 ms | 8320 KB | Output is correct |
6 | Correct | 8 ms | 8320 KB | Output is correct |
7 | Correct | 8 ms | 8320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8320 KB | Output is correct |
2 | Correct | 9 ms | 8448 KB | Output is correct |
3 | Correct | 11 ms | 8576 KB | Output is correct |
4 | Correct | 8 ms | 8320 KB | Output is correct |
5 | Correct | 8 ms | 8320 KB | Output is correct |
6 | Correct | 8 ms | 8320 KB | Output is correct |
7 | Correct | 8 ms | 8320 KB | Output is correct |
8 | Correct | 161 ms | 12408 KB | Output is correct |
9 | Correct | 162 ms | 12348 KB | Output is correct |
10 | Correct | 169 ms | 12792 KB | Output is correct |
11 | Correct | 181 ms | 13200 KB | Output is correct |
12 | Correct | 168 ms | 12536 KB | Output is correct |
13 | Correct | 151 ms | 12664 KB | Output is correct |
14 | Correct | 155 ms | 12568 KB | Output is correct |
15 | Correct | 188 ms | 12920 KB | Output is correct |
16 | Correct | 186 ms | 12952 KB | Output is correct |
17 | Correct | 156 ms | 12604 KB | Output is correct |
18 | Correct | 155 ms | 12664 KB | Output is correct |
19 | Correct | 150 ms | 12664 KB | Output is correct |
20 | Correct | 149 ms | 12920 KB | Output is correct |
21 | Correct | 143 ms | 12920 KB | Output is correct |
22 | Correct | 149 ms | 12536 KB | Output is correct |
23 | Correct | 158 ms | 12408 KB | Output is correct |
24 | Correct | 154 ms | 12408 KB | Output is correct |
25 | Correct | 157 ms | 12408 KB | Output is correct |
26 | Correct | 157 ms | 12408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 294 ms | 19192 KB | Output is correct |
2 | Correct | 284 ms | 19064 KB | Output is correct |
3 | Correct | 279 ms | 23624 KB | Output is correct |
4 | Correct | 321 ms | 24200 KB | Output is correct |
5 | Correct | 310 ms | 23928 KB | Output is correct |
6 | Correct | 232 ms | 22776 KB | Output is correct |
7 | Correct | 228 ms | 22648 KB | Output is correct |
8 | Correct | 227 ms | 22432 KB | Output is correct |
9 | Correct | 245 ms | 22520 KB | Output is correct |
10 | Correct | 221 ms | 22648 KB | Output is correct |
11 | Correct | 225 ms | 22392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8320 KB | Output is correct |
2 | Correct | 9 ms | 8448 KB | Output is correct |
3 | Correct | 11 ms | 8576 KB | Output is correct |
4 | Correct | 8 ms | 8320 KB | Output is correct |
5 | Correct | 8 ms | 8320 KB | Output is correct |
6 | Correct | 8 ms | 8320 KB | Output is correct |
7 | Correct | 8 ms | 8320 KB | Output is correct |
8 | Correct | 161 ms | 12408 KB | Output is correct |
9 | Correct | 162 ms | 12348 KB | Output is correct |
10 | Correct | 169 ms | 12792 KB | Output is correct |
11 | Correct | 181 ms | 13200 KB | Output is correct |
12 | Correct | 168 ms | 12536 KB | Output is correct |
13 | Correct | 151 ms | 12664 KB | Output is correct |
14 | Correct | 155 ms | 12568 KB | Output is correct |
15 | Correct | 188 ms | 12920 KB | Output is correct |
16 | Correct | 186 ms | 12952 KB | Output is correct |
17 | Correct | 156 ms | 12604 KB | Output is correct |
18 | Correct | 155 ms | 12664 KB | Output is correct |
19 | Correct | 150 ms | 12664 KB | Output is correct |
20 | Correct | 149 ms | 12920 KB | Output is correct |
21 | Correct | 143 ms | 12920 KB | Output is correct |
22 | Correct | 149 ms | 12536 KB | Output is correct |
23 | Correct | 158 ms | 12408 KB | Output is correct |
24 | Correct | 154 ms | 12408 KB | Output is correct |
25 | Correct | 157 ms | 12408 KB | Output is correct |
26 | Correct | 157 ms | 12408 KB | Output is correct |
27 | Correct | 294 ms | 19192 KB | Output is correct |
28 | Correct | 284 ms | 19064 KB | Output is correct |
29 | Correct | 279 ms | 23624 KB | Output is correct |
30 | Correct | 321 ms | 24200 KB | Output is correct |
31 | Correct | 310 ms | 23928 KB | Output is correct |
32 | Correct | 232 ms | 22776 KB | Output is correct |
33 | Correct | 228 ms | 22648 KB | Output is correct |
34 | Correct | 227 ms | 22432 KB | Output is correct |
35 | Correct | 245 ms | 22520 KB | Output is correct |
36 | Correct | 221 ms | 22648 KB | Output is correct |
37 | Correct | 225 ms | 22392 KB | Output is correct |
38 | Correct | 419 ms | 46456 KB | Output is correct |
39 | Correct | 436 ms | 52472 KB | Output is correct |
40 | Correct | 412 ms | 39160 KB | Output is correct |
41 | Correct | 445 ms | 50936 KB | Output is correct |
42 | Correct | 255 ms | 23656 KB | Output is correct |
43 | Correct | 238 ms | 23672 KB | Output is correct |
44 | Correct | 328 ms | 32652 KB | Output is correct |
45 | Correct | 328 ms | 32632 KB | Output is correct |
46 | Correct | 354 ms | 33060 KB | Output is correct |
47 | Correct | 256 ms | 23672 KB | Output is correct |
48 | Correct | 244 ms | 23544 KB | Output is correct |
49 | Correct | 367 ms | 32504 KB | Output is correct |
50 | Correct | 348 ms | 32564 KB | Output is correct |
51 | Correct | 360 ms | 33016 KB | Output is correct |
52 | Correct | 301 ms | 31480 KB | Output is correct |
53 | Correct | 375 ms | 39416 KB | Output is correct |
54 | Correct | 434 ms | 47404 KB | Output is correct |
55 | Correct | 394 ms | 39536 KB | Output is correct |