QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#845830#9221. Missing BoundariesHorcrux#WA 39ms6288kbC++232.5kb2025-01-06 19:34:132025-01-06 19:34:14

Judging History

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

  • [2025-01-06 19:34:14]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:6288kb
  • [2025-01-06 19:34:13]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
using u64 = unsigned 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] == 0) {
                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(i != p.size()) {
        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: 3764kb

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: 39ms
memory: 6288kb

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'