Submission #966888

# Submission time Handle Problem Language Result Execution time Memory
966888 2024-04-20T14:38:43 Z Jomnoi Alternating Heights (CCO22_day1problem1) C++17
25 / 25
743 ms 13940 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 3005;

int A[MAX_N], fur[MAX_N];
vector <int> graph[MAX_N];
int visited[MAX_N];

bool dfs(int u) {
    if (visited[u] == 2) return true;
    if (visited[u] == 1) return false;
    visited[u] = 1;

    for (auto v : graph[u]) {
        if (dfs(v) == false) return false;
    }
    visited[u] = 2;
    return true;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int N, K, Q;
    cin >> N >> K >> Q;

    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= N; i++) {
        int l = i, r = N;
        while (l <= r) {
            int mid = (l + r) / 2;

            for (int j = 1; j <= K; j++) {
                visited[j] = 0;
                graph[j].clear();
            }
            for (int j = i + 1; j <= mid; j++) {
                if (j % 2 == 1) graph[A[j]].push_back(A[j - 1]);
                else graph[A[j - 1]].push_back(A[j]);
            }

            bool ok = true;
            for (int j = 1; j <= K; j++) {
                if (visited[j] == 0 and dfs(j) == false) ok = false;
            }

            if (ok == true) l = mid + 1, fur[i] = mid;
            else r = mid - 1;
        }
    }

    while (Q--) {
        int x, y;
        cin >> x >> y;

        if (fur[x] >= y) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 143 ms 12884 KB Output is correct
2 Correct 142 ms 12880 KB Output is correct
3 Correct 152 ms 12792 KB Output is correct
4 Correct 105 ms 7240 KB Output is correct
5 Correct 112 ms 9300 KB Output is correct
6 Correct 139 ms 12840 KB Output is correct
7 Correct 140 ms 12884 KB Output is correct
8 Correct 140 ms 12880 KB Output is correct
9 Correct 146 ms 12884 KB Output is correct
10 Correct 208 ms 13144 KB Output is correct
11 Correct 341 ms 13900 KB Output is correct
12 Correct 338 ms 13280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 11012 KB Output is correct
2 Correct 115 ms 11088 KB Output is correct
3 Correct 117 ms 11312 KB Output is correct
4 Correct 96 ms 8328 KB Output is correct
5 Correct 109 ms 9504 KB Output is correct
6 Correct 113 ms 11088 KB Output is correct
7 Correct 117 ms 11220 KB Output is correct
8 Correct 121 ms 11228 KB Output is correct
9 Correct 143 ms 11716 KB Output is correct
10 Correct 118 ms 12112 KB Output is correct
11 Correct 120 ms 11972 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 353 ms 612 KB Output is correct
3 Correct 386 ms 848 KB Output is correct
4 Correct 13 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 540 KB Output is correct
7 Correct 248 ms 608 KB Output is correct
8 Correct 423 ms 848 KB Output is correct
9 Correct 561 ms 848 KB Output is correct
10 Correct 493 ms 600 KB Output is correct
11 Correct 649 ms 604 KB Output is correct
12 Correct 432 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 12884 KB Output is correct
2 Correct 142 ms 12880 KB Output is correct
3 Correct 152 ms 12792 KB Output is correct
4 Correct 105 ms 7240 KB Output is correct
5 Correct 112 ms 9300 KB Output is correct
6 Correct 139 ms 12840 KB Output is correct
7 Correct 140 ms 12884 KB Output is correct
8 Correct 140 ms 12880 KB Output is correct
9 Correct 146 ms 12884 KB Output is correct
10 Correct 208 ms 13144 KB Output is correct
11 Correct 341 ms 13900 KB Output is correct
12 Correct 338 ms 13280 KB Output is correct
13 Correct 123 ms 11012 KB Output is correct
14 Correct 115 ms 11088 KB Output is correct
15 Correct 117 ms 11312 KB Output is correct
16 Correct 96 ms 8328 KB Output is correct
17 Correct 109 ms 9504 KB Output is correct
18 Correct 113 ms 11088 KB Output is correct
19 Correct 117 ms 11220 KB Output is correct
20 Correct 121 ms 11228 KB Output is correct
21 Correct 143 ms 11716 KB Output is correct
22 Correct 118 ms 12112 KB Output is correct
23 Correct 120 ms 11972 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 353 ms 612 KB Output is correct
27 Correct 386 ms 848 KB Output is correct
28 Correct 13 ms 604 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 540 KB Output is correct
31 Correct 248 ms 608 KB Output is correct
32 Correct 423 ms 848 KB Output is correct
33 Correct 561 ms 848 KB Output is correct
34 Correct 493 ms 600 KB Output is correct
35 Correct 649 ms 604 KB Output is correct
36 Correct 432 ms 844 KB Output is correct
37 Correct 537 ms 13408 KB Output is correct
38 Correct 490 ms 13404 KB Output is correct
39 Correct 150 ms 12924 KB Output is correct
40 Correct 95 ms 8292 KB Output is correct
41 Correct 112 ms 9716 KB Output is correct
42 Correct 446 ms 13652 KB Output is correct
43 Correct 562 ms 13928 KB Output is correct
44 Correct 331 ms 13408 KB Output is correct
45 Correct 726 ms 13904 KB Output is correct
46 Correct 654 ms 13940 KB Output is correct
47 Correct 743 ms 13868 KB Output is correct