답안 #851648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851648 2023-09-20T10:20:34 Z khanhphucscratch Alternating Heights (CCO22_day1problem1) C++14
25 / 25
247 ms 9296 KB
#include<bits/stdc++.h>
using namespace std;
vector<int> ad[3001];
int k, f[3001], a[3001], val[3001], state[3001];
bool ok = 1, exist[3001];
void dfs(int u)
{
    state[u] = 1;
    for(int v : ad[u]) if(state[v] < 2){
        if(state[v] == 1){ok = 0; return;}
        else{
            dfs(v);
            if(ok == 0) return;
        }
    }
    state[u] = 2;
}
bool check(int l, int r)
{
    for(int i = 1; i <= k; i++){
        ad[i].clear();
        f[i] = 0; state[i] = 0; exist[i] = 0;
    }
    for(int i = l; i <= r; i++){
        exist[a[i]] = 1;
        if(i%2 == 1){
            if(i-1 >= l){
                ad[a[i]].push_back(a[i-1]);
                f[a[i-1]]++;
            }
            if(i+1 <= r){
                ad[a[i]].push_back(a[i+1]);
                f[a[i+1]]++;
            }
        }
    }
    ok = 1;
    for(int i = 1; i <= k; i++) if(f[i] == 0){
        dfs(i);
        if(ok == 0) return 0;
    }
    for(int i = 1; i <= k; i++) if(exist[i] == 1 && state[i] == 0) return 0;
    return ok;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin>>n>>k>>q;
    map<pair<int, int>, int> f;
    for(int i = 1; i <= n; i++) cin>>a[i];
    int j = 1;
    for(int i = 1; i <= n; i++){
        while(j <= n && check(i, j) == 1) j++;
        val[i] = j;
    }
    for(int i = 1; i <= q; i++){
        int l, r;
        cin>>l>>r;
        if(val[l] <= r) cout<<"NO"<<'\n';
        else cout<<"YES"<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 3408 KB Output is correct
2 Correct 140 ms 3340 KB Output is correct
3 Correct 147 ms 3424 KB Output is correct
4 Correct 110 ms 3408 KB Output is correct
5 Correct 147 ms 3460 KB Output is correct
6 Correct 138 ms 3408 KB Output is correct
7 Correct 138 ms 3504 KB Output is correct
8 Correct 137 ms 3416 KB Output is correct
9 Correct 141 ms 3536 KB Output is correct
10 Correct 164 ms 3972 KB Output is correct
11 Correct 151 ms 4432 KB Output is correct
12 Correct 166 ms 4500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 3604 KB Output is correct
2 Correct 131 ms 7504 KB Output is correct
3 Correct 136 ms 7760 KB Output is correct
4 Correct 112 ms 6688 KB Output is correct
5 Correct 128 ms 7016 KB Output is correct
6 Correct 127 ms 7508 KB Output is correct
7 Correct 136 ms 7792 KB Output is correct
8 Correct 132 ms 7760 KB Output is correct
9 Correct 144 ms 8016 KB Output is correct
10 Correct 127 ms 8528 KB Output is correct
11 Correct 128 ms 8456 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 79 ms 588 KB Output is correct
3 Correct 82 ms 592 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 51 ms 604 KB Output is correct
8 Correct 98 ms 568 KB Output is correct
9 Correct 116 ms 604 KB Output is correct
10 Correct 72 ms 572 KB Output is correct
11 Correct 103 ms 564 KB Output is correct
12 Correct 56 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 3408 KB Output is correct
2 Correct 140 ms 3340 KB Output is correct
3 Correct 147 ms 3424 KB Output is correct
4 Correct 110 ms 3408 KB Output is correct
5 Correct 147 ms 3460 KB Output is correct
6 Correct 138 ms 3408 KB Output is correct
7 Correct 138 ms 3504 KB Output is correct
8 Correct 137 ms 3416 KB Output is correct
9 Correct 141 ms 3536 KB Output is correct
10 Correct 164 ms 3972 KB Output is correct
11 Correct 151 ms 4432 KB Output is correct
12 Correct 166 ms 4500 KB Output is correct
13 Correct 129 ms 3604 KB Output is correct
14 Correct 131 ms 7504 KB Output is correct
15 Correct 136 ms 7760 KB Output is correct
16 Correct 112 ms 6688 KB Output is correct
17 Correct 128 ms 7016 KB Output is correct
18 Correct 127 ms 7508 KB Output is correct
19 Correct 136 ms 7792 KB Output is correct
20 Correct 132 ms 7760 KB Output is correct
21 Correct 144 ms 8016 KB Output is correct
22 Correct 127 ms 8528 KB Output is correct
23 Correct 128 ms 8456 KB Output is correct
24 Correct 0 ms 600 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 79 ms 588 KB Output is correct
27 Correct 82 ms 592 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 51 ms 604 KB Output is correct
32 Correct 98 ms 568 KB Output is correct
33 Correct 116 ms 604 KB Output is correct
34 Correct 72 ms 572 KB Output is correct
35 Correct 103 ms 564 KB Output is correct
36 Correct 56 ms 344 KB Output is correct
37 Correct 232 ms 9076 KB Output is correct
38 Correct 229 ms 8784 KB Output is correct
39 Correct 144 ms 8296 KB Output is correct
40 Correct 111 ms 6736 KB Output is correct
41 Correct 132 ms 7180 KB Output is correct
42 Correct 227 ms 9000 KB Output is correct
43 Correct 226 ms 9296 KB Output is correct
44 Correct 181 ms 9048 KB Output is correct
45 Correct 247 ms 9296 KB Output is correct
46 Correct 211 ms 9296 KB Output is correct
47 Correct 235 ms 9296 KB Output is correct