Submission #994200

# Submission time Handle Problem Language Result Execution time Memory
994200 2024-06-07T08:43:12 Z vjudge1 Jail (JOI22_jail) C++14
5 / 100
29 ms 4408 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 120'000;

int n, m;

bool cmp(const pii &a, const pii &b) {
    //
}

bool solve() {
    cin >> n;
    for(int i = 1; i <= n - 1; i++) {
        int a, b;
        cin >> a >> b;
        // do nothing
    }
    cin >> m;
    vector<pii > pairs_left, pairs_right;
    vector<bool> start_right, end_right, start_left, end_left, spot;
    start_right = end_right = start_left = end_left = spot = vector<bool> (1 + n, false);
    for(int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        if(a == b) {
            spot[a] = true;
        } else if(a < b) {
            start_right[a] = end_right[b] = true;
            pairs_right.pb(mp(a, b));
        } else {
            start_left[a] = end_left[b] = true;
            pairs_left.pb(mp(a, b));
        }
    }
    int cnt_left = 0, cnt_right = 0;
    for(int i = 1; i <= n; i++) {
        if(start_right[i]) {
            cnt_right++;
        }
        if(end_right[i]) {
            cnt_right--;
        }
        if(end_left[i]) {
            cnt_left++;
        }
        if(start_left[i]) {
            cnt_left--;
        }
        if(cnt_left > 0 && cnt_right > 0) {
            return false;
        }
        if(spot[i] && (cnt_left > 0 || cnt_right > 0)) {
            return false;
        }
    }
    sort(pairs_left.begin(), pairs_left.end());
    sort(pairs_right.begin(), pairs_right.end());
    int prev = 0;
    for(pii p : pairs_left) {
        if(p.se <= prev) {
            return false;
        }
        prev = p.se;
    }
    prev = 0;
    for(pii p : pairs_right) {
        if(p.se <= prev) {
            return false;
        }
        prev = p.se;
    }
    return true;
}

void reset() {
    //
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while(T--) {
        cout << (solve() ? "Yes" : "No") << "\n";
        reset();
    }
}

Compilation message

jail.cpp: In function 'bool cmp(const std::pair<int, int>&, const std::pair<int, int>&)':
jail.cpp:17:1: warning: no return statement in function returning non-void [-Wreturn-type]
   17 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 13 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 12 ms 468 KB Output is correct
10 Correct 12 ms 348 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 16 ms 456 KB Output is correct
13 Correct 17 ms 984 KB Output is correct
14 Correct 23 ms 1092 KB Output is correct
15 Correct 18 ms 3080 KB Output is correct
16 Correct 27 ms 4364 KB Output is correct
17 Correct 20 ms 3028 KB Output is correct
18 Correct 29 ms 4408 KB Output is correct
19 Correct 20 ms 3276 KB Output is correct
20 Correct 19 ms 3252 KB Output is correct
21 Correct 23 ms 3200 KB Output is correct
22 Correct 19 ms 3032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 13 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 12 ms 468 KB Output is correct
10 Correct 12 ms 348 KB Output is correct
11 Correct 3 ms 456 KB Output is correct
12 Correct 16 ms 456 KB Output is correct
13 Correct 17 ms 984 KB Output is correct
14 Correct 23 ms 1092 KB Output is correct
15 Correct 18 ms 3080 KB Output is correct
16 Correct 27 ms 4364 KB Output is correct
17 Correct 20 ms 3028 KB Output is correct
18 Correct 29 ms 4408 KB Output is correct
19 Correct 20 ms 3276 KB Output is correct
20 Correct 19 ms 3252 KB Output is correct
21 Correct 23 ms 3200 KB Output is correct
22 Correct 19 ms 3032 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -