QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532912#9221. Missing Boundariesucup-team004#WA 40ms6292kbC++202.4kb2024-08-25 14:22:202024-08-25 14:22:21

Judging History

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

  • [2024-08-25 14:22:21]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:6292kb
  • [2024-08-25 14:22:20]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int N, L;
    std::cin >> N >> L;
    
    std::vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i] >> b[i];
    }
    
    std::vector<std::array<int, 2>> seg;
    std::vector<std::array<int, 2>> p;
    seg.reserve(N);
    p.reserve(N);
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] != -1 && b[i] != -1) {
            seg.push_back({a[i], b[i]});
        } else if (a[i] != -1) {
            p.push_back({a[i], 0});
        } else if (b[i] != -1) {
            p.push_back({b[i], 1});
        } else {
            cnt++;
        }
    }
    std::sort(seg.begin(), seg.end());
    std::sort(p.begin(), p.end());
    for (int i = 1; i < seg.size(); i++) {
        if (seg[i][0] <= seg[i - 1][1]) {
            std::cout << "NIE\n";
            return;
        }
    }
    
    int i = 0;
    int cmin = 0;
    int cmax = 0;
    
    auto work = [&](int l, int r) -> bool {
        int j = i;
        while (i < p.size() && p[i][0] <= r) {
            if (p[i][0] < l) {
                return false;
            }
            i++;
        }
        cmax += r - l + 1 - (i - j);
        if (i == j) {
            cmin++;
        } else {
            for (int k = j + 1; k < i; k++) {
                if (p[k][0] == p[k - 1][0]) {
                    return false;
                }
                if (p[k][0] != p[k - 1][0] + 1 && p[k][1] == 0 && p[k - 1][1] == 1) {
                    cmin++;
                }
            }
            if (p[j][0] != l && p[j][1] == 0) {
                cmin++;
            }
            if (p[i - 1][0] != r && p[i - 1][1] == 1) {
                cmin++;
            }
        }
        return true;
    };
    int l = 1;
    for (auto [a, b] : seg) {
        if (a > l) {
            if (!work(l, a - 1)) {
                std::cout << "NIE\n";
                return;
            }
        }
        a = b + 1;
    }
    if (l <= L) {
        if (!work(l, L)) {
            std::cout << "NIE\n";
            return;
        }
    }
    
    if (cmin <= cnt && cnt <= cmax) {
        std::cout << "TAK\n";
    } else {
        std::cout << "NIE\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

詳細信息

Test #1:

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

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: 40ms
memory: 6292kb

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'