Submission #552691

# Submission time Handle Problem Language Result Execution time Memory
552691 2022-04-23T15:41:21 Z tht2005 Jail (JOI22_jail) C++17
5 / 100
69 ms 4960 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 120005;
int n, m, cnt[N], s[N], t[N], idx[N];

int main() {
    int q;
    scanf("%d", &q);
    while(q--) {
        scanf("%d", &n);
        for(int i = 1; i < n; ++i) {
            int a, b;
            scanf("%d %d", &a, &b);
            assert(a == i && b == i + 1);
        }
        memset(cnt, 0, (n + 1) * sizeof *cnt);
        scanf("%d", &m);
        for(int i = 1; i <= m; ++i) {
            scanf("%d %d", s + i, t + i);
            if(s[i] < t[i]) {
                ++cnt[s[i]];
                --cnt[t[i] + 1];
            }
        }
        for(int i = 1; i <= n; ++i) {
            cnt[i] += cnt[i - 1];
        }
        for(int i = 1; i <= m; ++i) {
            if(s[i] > t[i]) {
                swap(s[i], t[i]);
                if(cnt[s[i]] || cnt[t[i]]) {
                    puts("No");
                    goto nextQuery;
                }
            }
            idx[i] = i;
        }
        sort(idx + 1, idx + 1 + m, [&](int i, int j) {
            return s[i] < s[j];
        });
        for(int x = 1, r = 0; x <= m; ++x) {
            int i = idx[x];
            if(r > t[i]) {
                puts("No");
                goto nextQuery;
            }
            r = t[i];
        }
        puts("Yes");
nextQuery:;
    }
    return 0;
}

Compilation message

jail.cpp: In function 'int main()':
jail.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
jail.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |             scanf("%d %d", s + i, t + i);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 10 ms 340 KB Output is correct
5 Correct 20 ms 352 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 22 ms 1352 KB Output is correct
10 Correct 24 ms 1324 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 25 ms 1304 KB Output is correct
13 Correct 34 ms 2628 KB Output is correct
14 Correct 34 ms 2868 KB Output is correct
15 Correct 39 ms 2340 KB Output is correct
16 Correct 69 ms 3888 KB Output is correct
17 Correct 45 ms 3396 KB Output is correct
18 Correct 54 ms 4960 KB Output is correct
19 Correct 40 ms 3388 KB Output is correct
20 Correct 37 ms 3252 KB Output is correct
21 Correct 39 ms 3196 KB Output is correct
22 Correct 40 ms 3520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Runtime error 1 ms 432 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Runtime error 1 ms 432 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Runtime error 1 ms 432 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Runtime error 1 ms 432 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 436 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 10 ms 340 KB Output is correct
5 Correct 20 ms 352 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 2 ms 212 KB Output is correct
9 Correct 22 ms 1352 KB Output is correct
10 Correct 24 ms 1324 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 25 ms 1304 KB Output is correct
13 Correct 34 ms 2628 KB Output is correct
14 Correct 34 ms 2868 KB Output is correct
15 Correct 39 ms 2340 KB Output is correct
16 Correct 69 ms 3888 KB Output is correct
17 Correct 45 ms 3396 KB Output is correct
18 Correct 54 ms 4960 KB Output is correct
19 Correct 40 ms 3388 KB Output is correct
20 Correct 37 ms 3252 KB Output is correct
21 Correct 39 ms 3196 KB Output is correct
22 Correct 40 ms 3520 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Runtime error 1 ms 432 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -