Submission #936250

# Submission time Handle Problem Language Result Execution time Memory
936250 2024-03-01T13:32:28 Z sleepntsheep Alternating Heights (CCO22_day1problem1) C++17
25 / 25
475 ms 14136 KB
#include<bits/stdc++.h>

using namespace std;
#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
#define N 3005


int n, k, q, a[N], L[N];


basic_string<int> g[N];
int vs[N];

int cyclic(int u)
{
    vs[u] = 1;
    for (int v : g[u])
        if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
    vs[u] = 2;
    return 0;
}

int main()
{
    ShinLena;
    cin >> n >> k >> q;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        int l = 1, r = i; L[i] = i;
        while (l <= r)
        {
            memset(vs, 0, sizeof vs);
            for(int j = 1; j <= k; ++j) g[j].clear();
            int m = l+r>>1, ok = 1;
            for (int j = i; j > m; --j)
                if(j&1) g[a[j]].push_back(a[j-1]);
                else g[a[j-1]].push_back(a[j]);
            for (int j = i; ok && j > m; --j) if (!vs[a[j]] && cyclic(a[j])) ok = 0;

            if (ok) r = m - 1, L[i] = m;
            else l = m + 1;
        }
    }


    for (int x, y; q--;)
    {
        cin >> x >> y;
        if (x >= L[y]) cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}


Compilation message

Main.cpp: In function 'int cyclic(int)':
Main.cpp:19:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   19 |         if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
      |                           ~~~~~~~^~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:37:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |             int m = l+r>>1, ok = 1;
      |                     ~^~
# Verdict Execution time Memory Grader output
1 Correct 137 ms 12880 KB Output is correct
2 Correct 140 ms 12884 KB Output is correct
3 Correct 137 ms 12756 KB Output is correct
4 Correct 95 ms 7252 KB Output is correct
5 Correct 110 ms 9780 KB Output is correct
6 Correct 137 ms 12884 KB Output is correct
7 Correct 141 ms 12988 KB Output is correct
8 Correct 139 ms 12924 KB Output is correct
9 Correct 146 ms 12884 KB Output is correct
10 Correct 207 ms 13756 KB Output is correct
11 Correct 290 ms 13908 KB Output is correct
12 Correct 294 ms 13392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 11068 KB Output is correct
2 Correct 113 ms 11096 KB Output is correct
3 Correct 113 ms 11092 KB Output is correct
4 Correct 94 ms 8340 KB Output is correct
5 Correct 105 ms 9400 KB Output is correct
6 Correct 112 ms 11092 KB Output is correct
7 Correct 116 ms 11092 KB Output is correct
8 Correct 121 ms 11272 KB Output is correct
9 Correct 119 ms 11404 KB Output is correct
10 Correct 121 ms 12116 KB Output is correct
11 Correct 114 ms 12004 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 144 ms 840 KB Output is correct
3 Correct 165 ms 580 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 107 ms 580 KB Output is correct
8 Correct 202 ms 600 KB Output is correct
9 Correct 279 ms 580 KB Output is correct
10 Correct 289 ms 568 KB Output is correct
11 Correct 359 ms 584 KB Output is correct
12 Correct 223 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 137 ms 12880 KB Output is correct
2 Correct 140 ms 12884 KB Output is correct
3 Correct 137 ms 12756 KB Output is correct
4 Correct 95 ms 7252 KB Output is correct
5 Correct 110 ms 9780 KB Output is correct
6 Correct 137 ms 12884 KB Output is correct
7 Correct 141 ms 12988 KB Output is correct
8 Correct 139 ms 12924 KB Output is correct
9 Correct 146 ms 12884 KB Output is correct
10 Correct 207 ms 13756 KB Output is correct
11 Correct 290 ms 13908 KB Output is correct
12 Correct 294 ms 13392 KB Output is correct
13 Correct 118 ms 11068 KB Output is correct
14 Correct 113 ms 11096 KB Output is correct
15 Correct 113 ms 11092 KB Output is correct
16 Correct 94 ms 8340 KB Output is correct
17 Correct 105 ms 9400 KB Output is correct
18 Correct 112 ms 11092 KB Output is correct
19 Correct 116 ms 11092 KB Output is correct
20 Correct 121 ms 11272 KB Output is correct
21 Correct 119 ms 11404 KB Output is correct
22 Correct 121 ms 12116 KB Output is correct
23 Correct 114 ms 12004 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 144 ms 840 KB Output is correct
27 Correct 165 ms 580 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 107 ms 580 KB Output is correct
32 Correct 202 ms 600 KB Output is correct
33 Correct 279 ms 580 KB Output is correct
34 Correct 289 ms 568 KB Output is correct
35 Correct 359 ms 584 KB Output is correct
36 Correct 223 ms 572 KB Output is correct
37 Correct 304 ms 13816 KB Output is correct
38 Correct 272 ms 13596 KB Output is correct
39 Correct 139 ms 13128 KB Output is correct
40 Correct 102 ms 8272 KB Output is correct
41 Correct 110 ms 9756 KB Output is correct
42 Correct 257 ms 13368 KB Output is correct
43 Correct 341 ms 13908 KB Output is correct
44 Correct 238 ms 13392 KB Output is correct
45 Correct 472 ms 14136 KB Output is correct
46 Correct 447 ms 13908 KB Output is correct
47 Correct 475 ms 13900 KB Output is correct