Submission #973881

# Submission time Handle Problem Language Result Execution time Memory
973881 2024-05-02T12:14:26 Z SeenSiravit Alternating Heights (CCO22_day1problem1) C++14
0 / 25
1000 ms 11184 KB
#include<bits/stdc++.h>

using namespace std;

const int mxN = 3005;

int n,k,q;
int a[mxN];
vector<int> g[mxN];
int vis[mxN];
bool valid;

void dfs(int u){
    vis[u] = 1;

    for(auto v : g[u]){
        if(!valid) return ;

        if(vis[v] == 2) continue;
        else if(vis[v] == 1){
            valid = false;
            return ;
        }else{
            vis[v] = 1;
            dfs(v);
        }
    }

    vis[u] = 2;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0);

    cin>> n >> k >> q;

    for(int i=1;i<=n;i++) cin>> a[i];

    while(q--){
        int l,r;
        cin>> l >> r;

        for(int i=0;i<=k;i++) g[i].clear();

        int t = 1;

        for(int i=l;i<r;i++){
            if(t == 1) g[a[i]].push_back(a[i+1]);
            else g[a[i+1]].push_back(a[i]);

            t ^= 1;
        }

        // for(int i=1;i<=k;i++){
        //     printf("%d : " , i);
        //     for(auto j : g[i]) cout<< j <<" ";
        //     cout<< "\n";
        // }

        memset(vis , 0 , sizeof(vis));
        valid = true;
        dfs(a[l]);

        cout<< (valid ? "YES" : "NO") << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 6628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 601 ms 11184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 15 ms 856 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 6628 KB Time limit exceeded
2 Halted 0 ms 0 KB -