답안 #699106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
699106 2023-02-15T15:28:23 Z safaricola Alternating Heights (CCO22_day1problem1) C++17
25 / 25
254 ms 15744 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1; i <= n; i++) 
#define pb push_back
int n,a[3010],st=2,k,q,top[3010],cur,mini[3010],x,y;
bool rmv[3010][3010],vis[3010];
deque<int> adjl[3010];
bool ord(int a){
    if(vis[a] && top[a]==-1) return true;
    if(vis[a]) return false;
    vis[a] = true;
    for (int it: adjl[a]){
        if(ord(it)){
        return true;
        }
    }
    cur++;
    top[a]=cur;
    return false;
}
void remov(){
    bool flag=true;
    while(flag){
        flag=false;
        cur=0;
        memset(top, -1, sizeof(top));
        memset(vis, 0, sizeof(vis));
        for(int i=1; i<=n; i++)
            if(!vis[i]) 
                if(ord(i)){
                    flag=true;
                    i=n+1;
                    break;
                }
        if(flag){
            //cout<<st<<">\n";
            //remove edge;
            assert(st<=n+1);
            if(st%2==1){
                adjl[a[st]].pop_front();
            }else{
                adjl[a[st-1]].pop_front();
            }/*
            rep(i,n)
            for (int it: adjl[i]){
                if(rmv[i][it]) cout<<"rem "<<i<<' '<<it<<endl;
                else cout<<i<<' '<<it<<endl;
            }*/
            st++;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k>>q;
    mini[1]=1;
    rep(i,n){
        cin>>a[i];
        if(i==1)continue;
        if(i%2==1){
            adjl[a[i]].pb(a[i-1]);
            remov();
            //cout<<"ans:"<<st<<' '<<i<<endl;
            mini[i]=st-1;
        }else{
            adjl[a[i-1]].pb(a[i]);
            remov();
            //cout<<"ans:"<<st<<' '<<i<<endl;
            mini[i]=st-1;
        }
    }
    while(q--){
        cin>>x>>y;
        if(x<mini[y])cout<<"NO\n";
        else cout<<"YES\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 14896 KB Output is correct
2 Correct 201 ms 14716 KB Output is correct
3 Correct 207 ms 14756 KB Output is correct
4 Correct 114 ms 9228 KB Output is correct
5 Correct 127 ms 11312 KB Output is correct
6 Correct 199 ms 14716 KB Output is correct
7 Correct 199 ms 14720 KB Output is correct
8 Correct 201 ms 14788 KB Output is correct
9 Correct 202 ms 14844 KB Output is correct
10 Correct 218 ms 15192 KB Output is correct
11 Correct 214 ms 15700 KB Output is correct
12 Correct 218 ms 15056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 13004 KB Output is correct
2 Correct 144 ms 13068 KB Output is correct
3 Correct 143 ms 12992 KB Output is correct
4 Correct 137 ms 10268 KB Output is correct
5 Correct 134 ms 11404 KB Output is correct
6 Correct 143 ms 13000 KB Output is correct
7 Correct 151 ms 12992 KB Output is correct
8 Correct 141 ms 13020 KB Output is correct
9 Correct 150 ms 13388 KB Output is correct
10 Correct 140 ms 13952 KB Output is correct
11 Correct 150 ms 14000 KB Output is correct
12 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 73 ms 2388 KB Output is correct
3 Correct 73 ms 2408 KB Output is correct
4 Correct 54 ms 2412 KB Output is correct
5 Correct 2 ms 2364 KB Output is correct
6 Correct 2 ms 2388 KB Output is correct
7 Correct 66 ms 2424 KB Output is correct
8 Correct 81 ms 2428 KB Output is correct
9 Correct 91 ms 2388 KB Output is correct
10 Correct 92 ms 2388 KB Output is correct
11 Correct 103 ms 2540 KB Output is correct
12 Correct 84 ms 2408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 200 ms 14896 KB Output is correct
2 Correct 201 ms 14716 KB Output is correct
3 Correct 207 ms 14756 KB Output is correct
4 Correct 114 ms 9228 KB Output is correct
5 Correct 127 ms 11312 KB Output is correct
6 Correct 199 ms 14716 KB Output is correct
7 Correct 199 ms 14720 KB Output is correct
8 Correct 201 ms 14788 KB Output is correct
9 Correct 202 ms 14844 KB Output is correct
10 Correct 218 ms 15192 KB Output is correct
11 Correct 214 ms 15700 KB Output is correct
12 Correct 218 ms 15056 KB Output is correct
13 Correct 142 ms 13004 KB Output is correct
14 Correct 144 ms 13068 KB Output is correct
15 Correct 143 ms 12992 KB Output is correct
16 Correct 137 ms 10268 KB Output is correct
17 Correct 134 ms 11404 KB Output is correct
18 Correct 143 ms 13000 KB Output is correct
19 Correct 151 ms 12992 KB Output is correct
20 Correct 141 ms 13020 KB Output is correct
21 Correct 150 ms 13388 KB Output is correct
22 Correct 140 ms 13952 KB Output is correct
23 Correct 150 ms 14000 KB Output is correct
24 Correct 2 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 73 ms 2388 KB Output is correct
27 Correct 73 ms 2408 KB Output is correct
28 Correct 54 ms 2412 KB Output is correct
29 Correct 2 ms 2364 KB Output is correct
30 Correct 2 ms 2388 KB Output is correct
31 Correct 66 ms 2424 KB Output is correct
32 Correct 81 ms 2428 KB Output is correct
33 Correct 91 ms 2388 KB Output is correct
34 Correct 92 ms 2388 KB Output is correct
35 Correct 103 ms 2540 KB Output is correct
36 Correct 84 ms 2408 KB Output is correct
37 Correct 240 ms 15400 KB Output is correct
38 Correct 236 ms 15308 KB Output is correct
39 Correct 201 ms 14644 KB Output is correct
40 Correct 120 ms 10320 KB Output is correct
41 Correct 131 ms 11736 KB Output is correct
42 Correct 237 ms 15232 KB Output is correct
43 Correct 237 ms 15556 KB Output is correct
44 Correct 224 ms 15356 KB Output is correct
45 Correct 250 ms 15744 KB Output is correct
46 Correct 242 ms 15640 KB Output is correct
47 Correct 254 ms 15672 KB Output is correct