# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973908 | 2024-05-02T12:42:21 Z | SeenSiravit | Alternating Heights (CCO22_day1problem1) | C++14 | 1000 ms | 12116 KB |
#include<bits/stdc++.h> using namespace std; const int mxN = 3e3 + 5; int n,k,q; int a[mxN]; int ans[mxN]; vector<int> g[mxN]; int vis[mxN]; bool valid; void dfs(int u){ vis[u] = 1; for(auto v : g[u]){ if(vis[v] == 2) continue; else if(vis[v] == 1){ valid = false; return ; }else{ dfs(v); if(!valid) return ; } } vis[u] = 2; } int main(){ scanf("%d %d %d",&n,&k,&q); for(int i=1;i<=n;i++) scanf("%d",a+i); for(int i=1;i<=n;i++) ans[i] = n + 1; for(int l=1;l<=n;l++){ for(int r=l+1;r<=n;r++){ // clear edge and reset vis value for(int i=1;i<=k;i++) g[i].clear() , vis[i] = 0; // add edge int t = 1; for(int i=l;i<r;i++){ if(t == 1) g[a[i]].push_back(a[i+1]); else g[a[i+1]].push_back(a[i]); t ^= 1; } valid = true; for(int i=l;i<=r;i++){ if(vis[a[i]] == 0){ dfs(a[i]); if(!valid) break; } } if(!valid){ ans[l] = r; break; } } } // for(int i=1;i<=n;i++) printf("%d " , ans[i]); // printf("\n"); while(q--){ int l,r; scanf("%d %d" , &l , &r); cout<< (ans[l]<=r ? "NO" : "YES") << "\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 3412 KB | Output is correct |
2 | Correct | 176 ms | 3412 KB | Output is correct |
3 | Correct | 175 ms | 3412 KB | Output is correct |
4 | Correct | 163 ms | 3408 KB | Output is correct |
5 | Correct | 165 ms | 3992 KB | Output is correct |
6 | Correct | 178 ms | 3340 KB | Output is correct |
7 | Correct | 179 ms | 3412 KB | Output is correct |
8 | Correct | 182 ms | 3408 KB | Output is correct |
9 | Correct | 377 ms | 3636 KB | Output is correct |
10 | Execution timed out | 1022 ms | 344 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 176 ms | 3504 KB | Output is correct |
2 | Correct | 176 ms | 11092 KB | Output is correct |
3 | Correct | 179 ms | 10988 KB | Output is correct |
4 | Correct | 160 ms | 8528 KB | Output is correct |
5 | Correct | 160 ms | 9416 KB | Output is correct |
6 | Correct | 172 ms | 11088 KB | Output is correct |
7 | Correct | 183 ms | 11092 KB | Output is correct |
8 | Correct | 203 ms | 11056 KB | Output is correct |
9 | Correct | 188 ms | 11460 KB | Output is correct |
10 | Correct | 268 ms | 12116 KB | Output is correct |
11 | Correct | 262 ms | 11896 KB | Output is correct |
12 | Correct | 0 ms | 516 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Execution timed out | 1072 ms | 544 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 3412 KB | Output is correct |
2 | Correct | 176 ms | 3412 KB | Output is correct |
3 | Correct | 175 ms | 3412 KB | Output is correct |
4 | Correct | 163 ms | 3408 KB | Output is correct |
5 | Correct | 165 ms | 3992 KB | Output is correct |
6 | Correct | 178 ms | 3340 KB | Output is correct |
7 | Correct | 179 ms | 3412 KB | Output is correct |
8 | Correct | 182 ms | 3408 KB | Output is correct |
9 | Correct | 377 ms | 3636 KB | Output is correct |
10 | Execution timed out | 1022 ms | 344 KB | Time limit exceeded |
11 | Halted | 0 ms | 0 KB | - |