# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
581956 | 2022-06-23T08:36:13 Z | 조영욱(#8367) | Long Mansion (JOI17_long_mansion) | C++17 | 518 ms | 198272 KB |
#include <bits/stdc++.h> using namespace std; int n; int c[5000]; vector<int> vec[5001]; typedef pair<int,int> P; P dp[5001][5001]; int ll[5000]; int rr[5000]; P ans(int l,int r) { if (dp[l][r]!=P(-1,-1)) { return dp[l][r]; } if (l!=1&&rr[l-1]!=-1&&rr[l-1]<=r) { return dp[l][r]=ans(l-1,r); } if (r!=n&&ll[r]!=-1&&ll[r]>=l) { return dp[l][r]=ans(l,r+1); } return dp[l][r]=P(l,r); } int main(void) { scanf("%d",&n); for(int i=1;i<n;i++) { scanf("%d",&c[i]); } for(int i=1;i<=n;i++) { int k; scanf("%d",&k); for(int j=0;j<k;j++) { int x; scanf("%d",&x); vec[i].push_back(x); } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { dp[i][j]=P(-1,-1); } } for(int i=1;i<n;i++){ ll[i]=-1; rr[i]=-1; for(int j=i;j>0;j--) { bool flag=false; for(int k=0;k<vec[j].size();k++) { if (vec[j][k]==c[i]) { flag=true; break; } } if (flag) { ll[i]=j; break; } } for(int j=i+1;j<=n;j++) { bool flag=false; for(int k=0;k<vec[j].size();k++) { if (vec[j][k]==c[i]) { flag=true; break; } } if (flag) { rr[i]=j; break; } } } int q; scanf("%d",&q); for(int i=0;i<q;i++) { int x,y; scanf("%d %d",&x,&y); P got=ans(x,x); if (got.first<=y&&y<=got.second) { printf("YES\n"); } else { printf("NO\n"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 39892 KB | Output is correct |
2 | Correct | 77 ms | 83208 KB | Output is correct |
3 | Correct | 243 ms | 196584 KB | Output is correct |
4 | Correct | 22 ms | 39892 KB | Output is correct |
5 | Correct | 43 ms | 39904 KB | Output is correct |
6 | Correct | 29 ms | 39940 KB | Output is correct |
7 | Correct | 32 ms | 39892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 39892 KB | Output is correct |
2 | Correct | 77 ms | 83208 KB | Output is correct |
3 | Correct | 243 ms | 196584 KB | Output is correct |
4 | Correct | 22 ms | 39892 KB | Output is correct |
5 | Correct | 43 ms | 39904 KB | Output is correct |
6 | Correct | 29 ms | 39940 KB | Output is correct |
7 | Correct | 32 ms | 39892 KB | Output is correct |
8 | Correct | 154 ms | 41536 KB | Output is correct |
9 | Correct | 151 ms | 41496 KB | Output is correct |
10 | Correct | 210 ms | 84828 KB | Output is correct |
11 | Correct | 518 ms | 198272 KB | Output is correct |
12 | Correct | 131 ms | 14136 KB | Output is correct |
13 | Correct | 148 ms | 41588 KB | Output is correct |
14 | Correct | 143 ms | 41596 KB | Output is correct |
15 | Correct | 145 ms | 41752 KB | Output is correct |
16 | Correct | 190 ms | 41904 KB | Output is correct |
17 | Correct | 179 ms | 41600 KB | Output is correct |
18 | Correct | 145 ms | 41544 KB | Output is correct |
19 | Correct | 138 ms | 41676 KB | Output is correct |
20 | Correct | 151 ms | 41788 KB | Output is correct |
21 | Correct | 193 ms | 41940 KB | Output is correct |
22 | Correct | 155 ms | 41800 KB | Output is correct |
23 | Correct | 153 ms | 41500 KB | Output is correct |
24 | Correct | 174 ms | 41552 KB | Output is correct |
25 | Correct | 160 ms | 41556 KB | Output is correct |
26 | Correct | 158 ms | 41528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 39892 KB | Output is correct |
2 | Correct | 77 ms | 83208 KB | Output is correct |
3 | Correct | 243 ms | 196584 KB | Output is correct |
4 | Correct | 22 ms | 39892 KB | Output is correct |
5 | Correct | 43 ms | 39904 KB | Output is correct |
6 | Correct | 29 ms | 39940 KB | Output is correct |
7 | Correct | 32 ms | 39892 KB | Output is correct |
8 | Correct | 154 ms | 41536 KB | Output is correct |
9 | Correct | 151 ms | 41496 KB | Output is correct |
10 | Correct | 210 ms | 84828 KB | Output is correct |
11 | Correct | 518 ms | 198272 KB | Output is correct |
12 | Correct | 131 ms | 14136 KB | Output is correct |
13 | Correct | 148 ms | 41588 KB | Output is correct |
14 | Correct | 143 ms | 41596 KB | Output is correct |
15 | Correct | 145 ms | 41752 KB | Output is correct |
16 | Correct | 190 ms | 41904 KB | Output is correct |
17 | Correct | 179 ms | 41600 KB | Output is correct |
18 | Correct | 145 ms | 41544 KB | Output is correct |
19 | Correct | 138 ms | 41676 KB | Output is correct |
20 | Correct | 151 ms | 41788 KB | Output is correct |
21 | Correct | 193 ms | 41940 KB | Output is correct |
22 | Correct | 155 ms | 41800 KB | Output is correct |
23 | Correct | 153 ms | 41500 KB | Output is correct |
24 | Correct | 174 ms | 41552 KB | Output is correct |
25 | Correct | 160 ms | 41556 KB | Output is correct |
26 | Correct | 158 ms | 41528 KB | Output is correct |
27 | Incorrect | 1 ms | 340 KB | Output isn't correct |
28 | Halted | 0 ms | 0 KB | - |