QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#537388 | #9221. Missing Boundaries | ttbchimbu999# | WA | 84ms | 18792kb | C++20 | 2.3kb | 2024-08-30 11:53:36 | 2024-08-30 11:53:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, L;
pair<int, int> a[N];
vector<pair<int, int> > b;
map<int, bool> mark;
set<pair<int, int>> s;
void reinit() {
b.clear();
mark.clear();
s.clear();
}
void solve() {
cin >> n >> L;
bool ok = 1;
int cnt = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i].first >> a[i].second;
if (a[i].first != -1 && a[i].second == -1) {
b.push_back({a[i].first, 0});
a[i].second = a[i].first;
}
if (a[i].first == -1 && a[i].second != -1) {
b.push_back({a[i].second, 1});
a[i].first = a[i].second;
}
if (a[i].first == -1 && a[i].second == -1) ++cnt;
}
sort(a + 1, a + 1 + n);
//for(int i = 1; i <= n; i++) cout << a[i].first << ' ' << a[i].second << endl;
//return;
for(int i = 1; i <= n; i++) {
if (a[i].first != -1 && a[i].second != -1) {
auto it = s.lower_bound(a[i]);
if (it != s.end() && (*it).second >= a[i].first) {
//cerr << (*it).first << ' ' << (*it).second << endl;
ok = 0;
}
s.insert(a[i]);
}
}
if (!ok) {
cout << "NIE\n";
return;
}
sort(b.begin(), b.end());
int mn = 0, pre = 0;
for (auto &i : b) {
int pos = i.first, type = i.second;
if (pos == pre) ok = 0;
if (pos > 1 && type == 0 && !mark[pos - 1]) ++mn;
// cerr << "DB>> " << pos << " : " << mn << '\n';
pre = pos;
}
int mx = L - b.size();
// cerr << "DB>> " << mn << ' ' << mx << '\n';
if (!b.empty()) {
if (b.back().first < L && b.back().second == 1) ++mn;
}
else {
mn = 1;
mx = L;
}
if (ok && mn <= cnt && cnt <= mx) cout << "TAK\n";
else cout << "NIE\n";
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
// freopen("TEST.inp", "r", stdin);
// freopen("TEST.out", "w", stdout);
#else
// freopen("TEST.inp", "r", stdin);
// freopen("TEST.out", "w", stdout);
#endif
if (fopen("long.inp", "r")) {
freopen("long.inp", "r", stdin);
freopen("long.out", "w", stdout);
}
int t;
cin >> t;
while (t--) {
solve();
reinit();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
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: 84ms
memory: 18792kb
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'