답안 #954005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954005 2024-03-27T05:23:46 Z thiago_bastos Alternating Heights (CCO22_day1problem1) C++17
25 / 25
251 ms 11960 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 3e3 + 10;

int n, k, q, a[N], last[N], deg[N];
vector<int> adj[N];

bool is_dag(int l, int r) {
    queue<int> q;
    int count = 0;

    for(int i = 0; i < n; ++i) {
        deg[i] = 0;
        adj[i].clear();
    }

    for(int i = l + 1; i <= r; ++i) {
        if((i - l) % 2) {
            ++deg[a[i - 1]];
            adj[a[i]].push_back(a[i - 1]);
        } else {
            ++deg[a[i]];
            adj[a[i - 1]].push_back(a[i]);
        }
    }
    for(int i = 0; i < n; ++i) {    
        if(!deg[i]) {
            if(adj[i].size())
                q.push(i);
       } else
            ++count;
    }

    while(!q.empty()) {
        int u = q.front(); q.pop();

        for(int v : adj[u]) {
            if(--deg[v] == 0) {
                --count;
                q.push(v);
            }
        }
    }
    return count == 0;
}

void solve() {

    cin >> n >> k >> q;

    for(int i = 0; i < n; ++i) {cin >> a[i]; --a[i];}
    
    last[n - 1] = n - 1;

    for(int i = n - 2; i >= 0; --i) {
        last[i] = last[i + 1];
        while(!is_dag(i, last[i])) --last[i];
    }

    while(q--) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        cout << (last[l] >= r ? "YES\n" : "NO\n");
    }
}

int main() {
    int t = 1;
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    //cin >> t;
    while(t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 10836 KB Output is correct
2 Correct 191 ms 10752 KB Output is correct
3 Correct 186 ms 10800 KB Output is correct
4 Correct 99 ms 6716 KB Output is correct
5 Correct 115 ms 8296 KB Output is correct
6 Correct 186 ms 10796 KB Output is correct
7 Correct 193 ms 10860 KB Output is correct
8 Correct 190 ms 10836 KB Output is correct
9 Correct 191 ms 11064 KB Output is correct
10 Correct 206 ms 11296 KB Output is correct
11 Correct 179 ms 11960 KB Output is correct
12 Correct 216 ms 11344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 9556 KB Output is correct
2 Correct 130 ms 9708 KB Output is correct
3 Correct 124 ms 9480 KB Output is correct
4 Correct 102 ms 7760 KB Output is correct
5 Correct 116 ms 8272 KB Output is correct
6 Correct 124 ms 9552 KB Output is correct
7 Correct 126 ms 9768 KB Output is correct
8 Correct 125 ms 9624 KB Output is correct
9 Correct 142 ms 10064 KB Output is correct
10 Correct 125 ms 10580 KB Output is correct
11 Correct 124 ms 10468 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 81 ms 604 KB Output is correct
3 Correct 85 ms 632 KB Output is correct
4 Correct 57 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 72 ms 600 KB Output is correct
8 Correct 86 ms 624 KB Output is correct
9 Correct 92 ms 608 KB Output is correct
10 Correct 90 ms 600 KB Output is correct
11 Correct 94 ms 848 KB Output is correct
12 Correct 109 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 10836 KB Output is correct
2 Correct 191 ms 10752 KB Output is correct
3 Correct 186 ms 10800 KB Output is correct
4 Correct 99 ms 6716 KB Output is correct
5 Correct 115 ms 8296 KB Output is correct
6 Correct 186 ms 10796 KB Output is correct
7 Correct 193 ms 10860 KB Output is correct
8 Correct 190 ms 10836 KB Output is correct
9 Correct 191 ms 11064 KB Output is correct
10 Correct 206 ms 11296 KB Output is correct
11 Correct 179 ms 11960 KB Output is correct
12 Correct 216 ms 11344 KB Output is correct
13 Correct 127 ms 9556 KB Output is correct
14 Correct 130 ms 9708 KB Output is correct
15 Correct 124 ms 9480 KB Output is correct
16 Correct 102 ms 7760 KB Output is correct
17 Correct 116 ms 8272 KB Output is correct
18 Correct 124 ms 9552 KB Output is correct
19 Correct 126 ms 9768 KB Output is correct
20 Correct 125 ms 9624 KB Output is correct
21 Correct 142 ms 10064 KB Output is correct
22 Correct 125 ms 10580 KB Output is correct
23 Correct 124 ms 10468 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 81 ms 604 KB Output is correct
27 Correct 85 ms 632 KB Output is correct
28 Correct 57 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 72 ms 600 KB Output is correct
32 Correct 86 ms 624 KB Output is correct
33 Correct 92 ms 608 KB Output is correct
34 Correct 90 ms 600 KB Output is correct
35 Correct 94 ms 848 KB Output is correct
36 Correct 109 ms 624 KB Output is correct
37 Correct 227 ms 11604 KB Output is correct
38 Correct 222 ms 11376 KB Output is correct
39 Correct 187 ms 10808 KB Output is correct
40 Correct 101 ms 7776 KB Output is correct
41 Correct 112 ms 8560 KB Output is correct
42 Correct 215 ms 11764 KB Output is correct
43 Correct 236 ms 11860 KB Output is correct
44 Correct 251 ms 11368 KB Output is correct
45 Correct 225 ms 9344 KB Output is correct
46 Correct 237 ms 9244 KB Output is correct
47 Correct 217 ms 9296 KB Output is correct