Submission #966252

# Submission time Handle Problem Language Result Execution time Memory
966252 2024-04-19T15:22:04 Z vjudge1 Alternating Heights (CCO22_day1problem1) C++17
0 / 25
199 ms 4436 KB
#include <bits/stdc++.h>

using namespace std;

int n, k, q, arr[3010], dp[3010], x, y, vs[3010], idx, l, r, mid;
bool cnt;
pair<int, int> temp;
vector<int> g[3010];

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() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> k >> q;
    for(int i=1; i<=n; i++) {
        cin >> arr[i];
    }
    for(int i=1; i<=n; i++) {
        l=i; r=n;
        while(l<r) {
            mid = (l+r)>>1;
            for(int j=1; j<=n; j++) {
                g[j].clear();
            }
            cnt = 1;
            for(int j=i+1; j <= mid; j++) {
                if(j%2 == 0) {
                    g[arr[j-1]].push_back(arr[j]);
                } else {
                    g[arr[j]].push_back(arr[j-1]);
                }
            }
            for (int j = i+1; cnt && j <= mid; j++) if (!vs[arr[j]] && cyclic(arr[j])) cnt = 0;
            if(cnt) {
                r = mid;
            } else {
                l = mid+1;
            }
        }
        dp[i] = l;
    }
    while(q--) {
        cin >> x >> y;
        if(dp[x] <= y) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int cyclic(int)':
Main.cpp:14:34: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   14 |         if (vs[v] == 1 || !vs[v] && cyclic(v)) return 1;
      |                           ~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 4436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 199 ms 4408 KB Output isn't correct
2 Halted 0 ms 0 KB -