QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#531050#9221. Missing Boundariesucup-team3734#WA 319ms6284kbC++232.0kb2024-08-24 18:03:012024-08-24 18:03:02

Judging History

你现在查看的是最新测评结果

  • [2024-08-24 18:03:02]
  • 评测
  • 测评结果:WA
  • 用时:319ms
  • 内存:6284kb
  • [2024-08-24 18:03:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
const int inf = 1e9;

typedef long long i64;

struct seg {
    int l, r;
    bool gl, gr;

    bool operator<(const seg &o) const {
        return l < o.l;
    }
};

void solve() {
    int n, l;
    cin >> n >> l;
    vector<seg> segs;
    int u = 0;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        bool gl = false, gr = false;
        if (a == -1 && b == -1) {
            u++;
            continue;
        } else if (a == -1) {
            a = b - 1;
            gl = true;
        } else if (b == -1) {
            b = a + 1;
            gr = true;
        }
        segs.push_back({.l = a, .r = b, .gl = gl, .gr = gr});
    }
    segs.push_back({-inf, 0, false, false});
    segs.push_back({l + 1, inf, false, false});
    sort(segs.begin(), segs.end());
    for (int i = 0; i < (int) segs.size(); i++) {
        cerr << segs[i].l << " " << segs[i].r << " " << segs[i].gl << " " << segs[i].gr << endl;
    }
    for (int i = 0; i + 1 < (int) segs.size(); i++) {
        if (segs[i].r >= segs[i + 1].l) {
            cout << "NIE\n";
            return;
        }
    }
    int holes = 0;
    for (int i = 0; i + 1 < (int) segs.size(); i++) {
        if (segs[i].gr || segs[i + 1].gl) {
            continue;
        }
        if (segs[i].r + 1 != segs[i + 1].l) {
            holes++;
        }
    }
    int free = l;
    for (int i = 1; i + 1 < (int) segs.size(); i++) {
        free -= segs[i].r - segs[i].l + 1;
    }
    cerr << "holes = " << holes << " free = " << free << endl;
    if (holes > u) {
        cout << "NIE\n";
        return;
    }
    if (free < u) {
        cout << "NIE\n";
        return;
    }
    cout << "TAK\n";
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t --> 0) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 319ms
memory: 6284kb

input:

1
200000 1000000000
490669427 -1
224278942 224287156
821104480 -1
861696576 861702036
807438935 807440055
574078002 574083717
465630141 -1
195378188 -1
-1 13500961
-1 977536179
92893115 -1
-1 661145418
-1 215804863
-1 685338515
544348999 -1
465532902 -1
130346949 -1
-1 526666304
635604584 635605404
...

output:

NIE

result:

wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'