# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
781076 | 2023-07-12T17:16:32 Z | arnold518 | Alternating Heights (CCO22_day1problem1) | C++17 | 464 ms | 13780 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 3000; int N, K, Q; int A[MAXN+10], ans[MAXN+10]; int vis[MAXN+10]; vector<int> adj[MAXN+10]; bool dfs(int now) { vis[now]=1; bool ret=false; for(auto nxt : adj[now]) { if(vis[nxt]==1) return true; if(vis[nxt]==0) ret|=dfs(nxt); } vis[now]=2; return ret; } bool f(int l, int r) { for(int i=l; i<r; i++) { if(i%2==l%2) adj[A[i+1]].push_back(A[i]); else adj[A[i]].push_back(A[i+1]); } bool ret=false; for(int i=1; i<=K; i++) if(!vis[i]) ret|=dfs(i); for(int i=1; i<=K; i++) { adj[i].clear(), adj[i].shrink_to_fit(); vis[i]=0; } return !ret; } int main() { scanf("%d%d%d", &N, &K, &Q); for(int i=1; i<=N; i++) scanf("%d", &A[i]); for(int i=N; i>=1; i--) { int pos=N; if(i+2<=N) pos=ans[i+2]; for(; pos>=i && !f(i, pos); pos--) ; ans[i]=pos; } while(Q--) { int x, y; scanf("%d%d", &x, &y); if(ans[x]>=y) printf("YES\n"); else printf("NO\n"); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 171 ms | 12756 KB | Output is correct |
2 | Correct | 168 ms | 12656 KB | Output is correct |
3 | Correct | 185 ms | 12672 KB | Output is correct |
4 | Correct | 138 ms | 7284 KB | Output is correct |
5 | Correct | 151 ms | 9320 KB | Output is correct |
6 | Correct | 167 ms | 12672 KB | Output is correct |
7 | Correct | 167 ms | 12688 KB | Output is correct |
8 | Correct | 179 ms | 12768 KB | Output is correct |
9 | Correct | 171 ms | 12876 KB | Output is correct |
10 | Correct | 188 ms | 13124 KB | Output is correct |
11 | Correct | 183 ms | 13780 KB | Output is correct |
12 | Correct | 202 ms | 12984 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 164 ms | 11036 KB | Output is correct |
2 | Correct | 155 ms | 10940 KB | Output is correct |
3 | Correct | 161 ms | 10952 KB | Output is correct |
4 | Correct | 139 ms | 8200 KB | Output is correct |
5 | Correct | 170 ms | 9356 KB | Output is correct |
6 | Correct | 156 ms | 10948 KB | Output is correct |
7 | Correct | 157 ms | 10944 KB | Output is correct |
8 | Correct | 167 ms | 11048 KB | Output is correct |
9 | Correct | 160 ms | 11384 KB | Output is correct |
10 | Correct | 155 ms | 11916 KB | Output is correct |
11 | Correct | 161 ms | 11872 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 376 KB | Output is correct |
2 | Correct | 206 ms | 436 KB | Output is correct |
3 | Correct | 182 ms | 424 KB | Output is correct |
4 | Correct | 2 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 148 ms | 424 KB | Output is correct |
8 | Correct | 208 ms | 436 KB | Output is correct |
9 | Correct | 208 ms | 564 KB | Output is correct |
10 | Correct | 245 ms | 428 KB | Output is correct |
11 | Correct | 182 ms | 444 KB | Output is correct |
12 | Correct | 366 ms | 428 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 171 ms | 12756 KB | Output is correct |
2 | Correct | 168 ms | 12656 KB | Output is correct |
3 | Correct | 185 ms | 12672 KB | Output is correct |
4 | Correct | 138 ms | 7284 KB | Output is correct |
5 | Correct | 151 ms | 9320 KB | Output is correct |
6 | Correct | 167 ms | 12672 KB | Output is correct |
7 | Correct | 167 ms | 12688 KB | Output is correct |
8 | Correct | 179 ms | 12768 KB | Output is correct |
9 | Correct | 171 ms | 12876 KB | Output is correct |
10 | Correct | 188 ms | 13124 KB | Output is correct |
11 | Correct | 183 ms | 13780 KB | Output is correct |
12 | Correct | 202 ms | 12984 KB | Output is correct |
13 | Correct | 164 ms | 11036 KB | Output is correct |
14 | Correct | 155 ms | 10940 KB | Output is correct |
15 | Correct | 161 ms | 10952 KB | Output is correct |
16 | Correct | 139 ms | 8200 KB | Output is correct |
17 | Correct | 170 ms | 9356 KB | Output is correct |
18 | Correct | 156 ms | 10948 KB | Output is correct |
19 | Correct | 157 ms | 10944 KB | Output is correct |
20 | Correct | 167 ms | 11048 KB | Output is correct |
21 | Correct | 160 ms | 11384 KB | Output is correct |
22 | Correct | 155 ms | 11916 KB | Output is correct |
23 | Correct | 161 ms | 11872 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 376 KB | Output is correct |
26 | Correct | 206 ms | 436 KB | Output is correct |
27 | Correct | 182 ms | 424 KB | Output is correct |
28 | Correct | 2 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 148 ms | 424 KB | Output is correct |
32 | Correct | 208 ms | 436 KB | Output is correct |
33 | Correct | 208 ms | 564 KB | Output is correct |
34 | Correct | 245 ms | 428 KB | Output is correct |
35 | Correct | 182 ms | 444 KB | Output is correct |
36 | Correct | 366 ms | 428 KB | Output is correct |
37 | Correct | 397 ms | 13288 KB | Output is correct |
38 | Correct | 384 ms | 13208 KB | Output is correct |
39 | Correct | 185 ms | 12684 KB | Output is correct |
40 | Correct | 138 ms | 8184 KB | Output is correct |
41 | Correct | 158 ms | 9696 KB | Output is correct |
42 | Correct | 358 ms | 13244 KB | Output is correct |
43 | Correct | 464 ms | 13568 KB | Output is correct |
44 | Correct | 351 ms | 13360 KB | Output is correct |
45 | Correct | 354 ms | 13684 KB | Output is correct |
46 | Correct | 423 ms | 13756 KB | Output is correct |
47 | Correct | 340 ms | 13716 KB | Output is correct |