답안 #638576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638576 2022-09-06T12:22:11 Z morasha3 Alternating Heights (CCO22_day1problem1) C++17
25 / 25
777 ms 13900 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef   double ld;
const ll mod=1e9+7;
#define endl '\n'
bool dfs(vector<vector<int>>& v)
{
    int n = v.size();
    vector<int> deg(n);
    for (int a = 0; a < n; a++)
        for (int b : v[a])
            deg[b]++;

    vector<int> q;
    q.reserve(n);
    for (int i = 0; i < n; i++)
        if (deg[i] == 0)
            q.push_back(i);
    for (int rep = 0; rep < q.size(); rep++)
    {
        int c = q[rep];
        for (auto nxt : v[c])
        {
            deg[nxt]--;
            if (deg[nxt] == 0)
                q.push_back(nxt);
        }
    }
    return n>q.size();
}


int32_t main()
{
    //freopen("jumping.in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k,q;
    cin>>n>>k>>q;
    ll arr[n];
    for(int i=0; i<n; i++)
        {cin>>arr[i]; arr[i]--;}
  vector<int> can(n);
    for (int rep : {0, 1}) {
        for (int l = rep, r = l; l < n; l += 2) {
            while (r < n) {
                vector<vector<int>> adj(k);
                for (int i = l; i < r; i++) {
                    if (i % 2 == l % 2) adj[arr[i]].push_back(arr[i + 1]);
                    else adj[arr[i + 1]].push_back(arr[i]);
                }
                if (dfs(adj)) break;
                r++;
            }
            can[l] = r;
        }
    }
    while (q--) {
        int l, r; cin >> l >> r, --l, --r;
        if (can[l] <= r) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }


    return 0;

}

Compilation message

Main.cpp: In function 'bool dfs(std::vector<std::vector<int> >&)':
Main.cpp:20:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int rep = 0; rep < q.size(); rep++)
      |                       ~~~~^~~~~~~~~~
Main.cpp:30:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     return n>q.size();
      |            ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 3276 KB Output is correct
2 Correct 150 ms 3344 KB Output is correct
3 Correct 150 ms 3280 KB Output is correct
4 Correct 110 ms 3276 KB Output is correct
5 Correct 130 ms 3340 KB Output is correct
6 Correct 163 ms 3264 KB Output is correct
7 Correct 153 ms 3272 KB Output is correct
8 Correct 153 ms 3324 KB Output is correct
9 Correct 166 ms 3372 KB Output is correct
10 Correct 231 ms 13016 KB Output is correct
11 Correct 268 ms 13708 KB Output is correct
12 Correct 304 ms 12936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 3332 KB Output is correct
2 Correct 140 ms 3404 KB Output is correct
3 Correct 148 ms 3340 KB Output is correct
4 Correct 117 ms 4308 KB Output is correct
5 Correct 126 ms 3528 KB Output is correct
6 Correct 139 ms 3276 KB Output is correct
7 Correct 139 ms 3296 KB Output is correct
8 Correct 146 ms 3408 KB Output is correct
9 Correct 147 ms 3748 KB Output is correct
10 Correct 143 ms 4356 KB Output is correct
11 Correct 144 ms 4300 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 423 ms 432 KB Output is correct
3 Correct 486 ms 464 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 329 ms 432 KB Output is correct
8 Correct 541 ms 468 KB Output is correct
9 Correct 720 ms 476 KB Output is correct
10 Correct 580 ms 564 KB Output is correct
11 Correct 651 ms 464 KB Output is correct
12 Correct 483 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 3276 KB Output is correct
2 Correct 150 ms 3344 KB Output is correct
3 Correct 150 ms 3280 KB Output is correct
4 Correct 110 ms 3276 KB Output is correct
5 Correct 130 ms 3340 KB Output is correct
6 Correct 163 ms 3264 KB Output is correct
7 Correct 153 ms 3272 KB Output is correct
8 Correct 153 ms 3324 KB Output is correct
9 Correct 166 ms 3372 KB Output is correct
10 Correct 231 ms 13016 KB Output is correct
11 Correct 268 ms 13708 KB Output is correct
12 Correct 304 ms 12936 KB Output is correct
13 Correct 147 ms 3332 KB Output is correct
14 Correct 140 ms 3404 KB Output is correct
15 Correct 148 ms 3340 KB Output is correct
16 Correct 117 ms 4308 KB Output is correct
17 Correct 126 ms 3528 KB Output is correct
18 Correct 139 ms 3276 KB Output is correct
19 Correct 139 ms 3296 KB Output is correct
20 Correct 146 ms 3408 KB Output is correct
21 Correct 147 ms 3748 KB Output is correct
22 Correct 143 ms 4356 KB Output is correct
23 Correct 144 ms 4300 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 423 ms 432 KB Output is correct
27 Correct 486 ms 464 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 329 ms 432 KB Output is correct
32 Correct 541 ms 468 KB Output is correct
33 Correct 720 ms 476 KB Output is correct
34 Correct 580 ms 564 KB Output is correct
35 Correct 651 ms 464 KB Output is correct
36 Correct 483 ms 416 KB Output is correct
37 Correct 690 ms 13392 KB Output is correct
38 Correct 611 ms 13204 KB Output is correct
39 Correct 156 ms 12756 KB Output is correct
40 Correct 117 ms 8140 KB Output is correct
41 Correct 135 ms 9676 KB Output is correct
42 Correct 535 ms 13388 KB Output is correct
43 Correct 719 ms 13584 KB Output is correct
44 Correct 502 ms 13264 KB Output is correct
45 Correct 770 ms 13900 KB Output is correct
46 Correct 737 ms 13776 KB Output is correct
47 Correct 777 ms 13736 KB Output is correct