Submission #966251

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

using namespace std;

vector<int> vc[2020];
int n,k,q, arr[2020], dp[2020], vis[2020];

bool cycle(int u){
    vis[u] = 1;
    for(auto x:vc[u]) if(vis[x] || (!vis[x] && cycle(x))) return true;
    vis[u] = 2;
    return false;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> k >> q;
    for(int i = 1; i<=n; ++i){
        cin >> arr[i];
        int l = 1, r = i;
        dp[i] = i;
        while(l <= r){
            int mid = (l + r) >> 1;
            bool check = true;
            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]].emplace_back(arr[j - 1]);
                else vc[arr[j - 1]].emplace_back(arr[j]);
            }
            for(int j = i; j>mid && check; --j) if(!vis[j] && cycle(arr[j])) check = false;
            if(check){
                dp[i] = mid;
                r = mid - 1;
            }
            else l = mid+1;
        }
    }
    while(q--){
        int x, y; cin >> x >> y;
        dp[y] <= x ? cout << "YES\n" : cout << "NO\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -