답안 #886425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886425 2023-12-12T06:35:48 Z tsumondai Alternating Heights (CCO22_day1problem1) C++14
25 / 25
268 ms 14148 KB
#include <bits/stdc++.h>
using namespace std;

#define Task "CCO22_day1problem1"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e3 + 5;

const int oo = 1e9, mod = 1e9 + 7;

int n, m, k;
int f[3001], a[3001], val[3001], state[3001];
bool ok = 1, exist[3001];
vector<int> adj[N];

void dfs(int u) {
    state[u] = 1;
    for (int v : adj[u]) if (state[v] < 2) {
            if (state[v] == 1) {ok = 0; return;}
            else {
                dfs(v);
                if (ok == 0) return;
            }
        }
    state[u] = 2;
}

bool check(int l, int r) {
    for (int i = 1; i <= k; i++) {
        adj[i].clear();
        f[i] = 0; state[i] = 0; exist[i] = 0;
    }
    for (int i = l; i <= r; i++) {
        exist[a[i]] = 1;
        if (i % 2 == 1) {
            if (i - 1 >= l) {
                adj[a[i]].push_back(a[i - 1]);
                f[a[i - 1]]++;
            }
            if (i + 1 <= r) {
                adj[a[i]].push_back(a[i + 1]);
                f[a[i + 1]]++;
            }
        }
    }
    ok = 1;
    for (int i = 1; i <= k; i++) if (f[i] == 0) {
            dfs(i);
            if (ok == 0) return 0;
        }
    for (int i = 1; i <= k; i++) if (exist[i] == 1 && state[i] == 0) return 0;
    return ok;
}

void process() {
    int n, q;
    cin >> n >> k >> q;
    map<pair<int, int>, int> f;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int j = 1;
    for (int i = 1; i <= n; i++) {
        while (j <= n && check(i, j) == 1) j++;
        val[i] = j;
    }
    for (int i = 1; i <= q; i++) {
        int l, r;
        cin >> l >> r;
        if (val[l] <= r) cout << "NO" << '\n';
        else cout << "YES" << '\n';
    }
    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    if (fopen(Task".INP", "r")) {
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

// dont stop

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(Task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(Task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 12884 KB Output is correct
2 Correct 137 ms 12800 KB Output is correct
3 Correct 137 ms 12716 KB Output is correct
4 Correct 108 ms 7252 KB Output is correct
5 Correct 120 ms 9348 KB Output is correct
6 Correct 139 ms 12780 KB Output is correct
7 Correct 140 ms 12936 KB Output is correct
8 Correct 139 ms 12880 KB Output is correct
9 Correct 145 ms 13260 KB Output is correct
10 Correct 155 ms 13396 KB Output is correct
11 Correct 153 ms 13940 KB Output is correct
12 Correct 160 ms 13136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 11088 KB Output is correct
2 Correct 126 ms 11136 KB Output is correct
3 Correct 126 ms 10992 KB Output is correct
4 Correct 108 ms 8344 KB Output is correct
5 Correct 119 ms 9396 KB Output is correct
6 Correct 125 ms 11092 KB Output is correct
7 Correct 163 ms 11092 KB Output is correct
8 Correct 126 ms 11240 KB Output is correct
9 Correct 140 ms 11552 KB Output is correct
10 Correct 126 ms 12100 KB Output is correct
11 Correct 131 ms 12116 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 82 ms 604 KB Output is correct
3 Correct 84 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 55 ms 604 KB Output is correct
8 Correct 94 ms 604 KB Output is correct
9 Correct 112 ms 604 KB Output is correct
10 Correct 68 ms 600 KB Output is correct
11 Correct 107 ms 856 KB Output is correct
12 Correct 54 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 142 ms 12884 KB Output is correct
2 Correct 137 ms 12800 KB Output is correct
3 Correct 137 ms 12716 KB Output is correct
4 Correct 108 ms 7252 KB Output is correct
5 Correct 120 ms 9348 KB Output is correct
6 Correct 139 ms 12780 KB Output is correct
7 Correct 140 ms 12936 KB Output is correct
8 Correct 139 ms 12880 KB Output is correct
9 Correct 145 ms 13260 KB Output is correct
10 Correct 155 ms 13396 KB Output is correct
11 Correct 153 ms 13940 KB Output is correct
12 Correct 160 ms 13136 KB Output is correct
13 Correct 128 ms 11088 KB Output is correct
14 Correct 126 ms 11136 KB Output is correct
15 Correct 126 ms 10992 KB Output is correct
16 Correct 108 ms 8344 KB Output is correct
17 Correct 119 ms 9396 KB Output is correct
18 Correct 125 ms 11092 KB Output is correct
19 Correct 163 ms 11092 KB Output is correct
20 Correct 126 ms 11240 KB Output is correct
21 Correct 140 ms 11552 KB Output is correct
22 Correct 126 ms 12100 KB Output is correct
23 Correct 131 ms 12116 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 82 ms 604 KB Output is correct
27 Correct 84 ms 604 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 55 ms 604 KB Output is correct
32 Correct 94 ms 604 KB Output is correct
33 Correct 112 ms 604 KB Output is correct
34 Correct 68 ms 600 KB Output is correct
35 Correct 107 ms 856 KB Output is correct
36 Correct 54 ms 756 KB Output is correct
37 Correct 238 ms 13496 KB Output is correct
38 Correct 230 ms 13412 KB Output is correct
39 Correct 139 ms 12880 KB Output is correct
40 Correct 109 ms 8464 KB Output is correct
41 Correct 123 ms 9752 KB Output is correct
42 Correct 226 ms 13480 KB Output is correct
43 Correct 220 ms 13908 KB Output is correct
44 Correct 172 ms 13392 KB Output is correct
45 Correct 239 ms 14148 KB Output is correct
46 Correct 211 ms 13904 KB Output is correct
47 Correct 268 ms 13900 KB Output is correct