Submission #967234

# Submission time Handle Problem Language Result Execution time Memory
967234 2024-04-21T14:40:01 Z vjudge1 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
621 ms 13904 KB
#include<bits/stdc++.h>

using namespace std;

int n,k,q, arr[3030], vis[3030], ans[3030], ck;
vector<int> vc[3030];

int check(int u){
    vis[u] = 1;
    for (int v : vc[u]) if(vis[v] == 1 || !vis[v] && check(v)) return 1;
    vis[u] = 2;
    return 0;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> k >> q;
    for(int i = 1; i<=n; ++i) cin >> arr[i];
    for(int i = 1; i<=n; ++i){
        int l = i, r = n;
        ans[i] = i;
        while(l <= r){
            int mid = (l + r) >> 1, ck = 1;
            memset(vis, 0, sizeof(vis));
            for(int j = 1; j<=k; ++j) vc[j].clear();
            for(int j = i; j<mid; ++j){
                if(j&1) vc[arr[j+1]].push_back(arr[j]);
                else vc[arr[j]].push_back(arr[j+1]);
            }
            for(int j = i; j<=mid; ++j){
                if(!vis[arr[j]] && check(arr[j])){
                    ck = 0;
                    break;
                }
            }
            if(ck){
                ans[i] = mid;
                l = mid+1;
            }
            else r = mid - 1;
        }
    }
    while(q--){
        int l, r; cin >> l >> r;
        ans[l] >= r ? cout << "YES\n": cout << "NO\n";
    }
}

Compilation message

Main.cpp: In function 'int check(int)':
Main.cpp:10:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   10 |     for (int v : vc[u]) if(vis[v] == 1 || !vis[v] && check(v)) return 1;
      |                                           ~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 138 ms 12908 KB Output is correct
2 Correct 152 ms 12824 KB Output is correct
3 Correct 139 ms 12864 KB Output is correct
4 Correct 96 ms 7516 KB Output is correct
5 Correct 108 ms 9384 KB Output is correct
6 Correct 136 ms 12884 KB Output is correct
7 Correct 137 ms 12856 KB Output is correct
8 Correct 138 ms 12780 KB Output is correct
9 Correct 151 ms 13140 KB Output is correct
10 Correct 203 ms 13392 KB Output is correct
11 Correct 337 ms 13904 KB Output is correct
12 Correct 287 ms 13280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 11088 KB Output is correct
2 Correct 112 ms 11156 KB Output is correct
3 Correct 118 ms 10916 KB Output is correct
4 Correct 116 ms 8324 KB Output is correct
5 Correct 118 ms 9524 KB Output is correct
6 Correct 112 ms 11284 KB Output is correct
7 Correct 125 ms 11316 KB Output is correct
8 Correct 114 ms 11148 KB Output is correct
9 Correct 118 ms 11348 KB Output is correct
10 Correct 118 ms 11912 KB Output is correct
11 Correct 122 ms 12372 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 163 ms 600 KB Output is correct
3 Correct 191 ms 844 KB Output is correct
4 Correct 16 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 123 ms 604 KB Output is correct
8 Correct 234 ms 604 KB Output is correct
9 Correct 313 ms 604 KB Output is correct
10 Correct 384 ms 604 KB Output is correct
11 Correct 537 ms 852 KB Output is correct
12 Correct 339 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 12908 KB Output is correct
2 Correct 152 ms 12824 KB Output is correct
3 Correct 139 ms 12864 KB Output is correct
4 Correct 96 ms 7516 KB Output is correct
5 Correct 108 ms 9384 KB Output is correct
6 Correct 136 ms 12884 KB Output is correct
7 Correct 137 ms 12856 KB Output is correct
8 Correct 138 ms 12780 KB Output is correct
9 Correct 151 ms 13140 KB Output is correct
10 Correct 203 ms 13392 KB Output is correct
11 Correct 337 ms 13904 KB Output is correct
12 Correct 287 ms 13280 KB Output is correct
13 Correct 130 ms 11088 KB Output is correct
14 Correct 112 ms 11156 KB Output is correct
15 Correct 118 ms 10916 KB Output is correct
16 Correct 116 ms 8324 KB Output is correct
17 Correct 118 ms 9524 KB Output is correct
18 Correct 112 ms 11284 KB Output is correct
19 Correct 125 ms 11316 KB Output is correct
20 Correct 114 ms 11148 KB Output is correct
21 Correct 118 ms 11348 KB Output is correct
22 Correct 118 ms 11912 KB Output is correct
23 Correct 122 ms 12372 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 163 ms 600 KB Output is correct
27 Correct 191 ms 844 KB Output is correct
28 Correct 16 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 123 ms 604 KB Output is correct
32 Correct 234 ms 604 KB Output is correct
33 Correct 313 ms 604 KB Output is correct
34 Correct 384 ms 604 KB Output is correct
35 Correct 537 ms 852 KB Output is correct
36 Correct 339 ms 604 KB Output is correct
37 Correct 348 ms 13556 KB Output is correct
38 Correct 312 ms 13168 KB Output is correct
39 Correct 140 ms 12780 KB Output is correct
40 Correct 109 ms 8276 KB Output is correct
41 Correct 111 ms 9812 KB Output is correct
42 Correct 283 ms 13400 KB Output is correct
43 Correct 402 ms 13648 KB Output is correct
44 Correct 270 ms 13656 KB Output is correct
45 Correct 566 ms 13904 KB Output is correct
46 Correct 621 ms 13772 KB Output is correct
47 Correct 562 ms 13852 KB Output is correct