QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#637939 | #9221. Missing Boundaries | propane# | WA | 33ms | 7828kb | C++20 | 2.2kb | 2024-10-13 14:25:49 | 2024-10-13 14:25:49 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
vector<pair<int, int> > p;
int cnt = 0;
int n, L;
cin >> n >> L;
for(int i = 0; i < n; i++){
int l, r;
cin >> l >> r;
if (l == -1 and r == -1){
cnt += 1;
}
else{
p.push_back({l, r});
}
}
if (p.empty()){
cout << (n <= L ? "TAK" : "NIE") << '\n';
continue;
}
sort(p.begin(), p.end(), [&](pair<int, int> a, pair<int, int> b){
return max(a.first, a.second) < max(b.first, b.second);
});
vector<pair<int, int> > q;
for(auto [l, r] : p){
if (l == -1) q.push_back({r, r});
else q.push_back({l, l});
}
bool ok = true;
for(int i = 0; i + 1 < q.size(); i++){
if (q[i].second >= q[i + 1].first){
ok = false;
break;
}
}
for(auto [l, r] : q){
if (l <= 0 or r > L){
ok = false;
break;
}
}
int lack = 0;
if (q[0].first != 1 and p[0].first != -1) lack += 1;
if (q.back().second != L and p.back().second != -1) lack += 1;
for(int i = 0; i + 1 < q.size(); i++){
int len = q[i + 1].first - q[i].second - 1;
if (len > 0 and p[i].second != -1 and p[i + 1].first != -1){
lack += 1;
}
}
if (cnt < lack){
ok = false;
}
int mx = q[0].first - 1 + L - q.back().second;
for(int i = 0; i + 1 < q.size(); i++){
mx += q[i + 1].first - q[i].second - 1;
}
if (mx < cnt){
ok = false;
}
cout << (ok ? "TAK" : "NIE") << '\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
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: 33ms
memory: 7828kb
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'