QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#336851 | #6308. Magic | Watware | WA | 72ms | 6980kb | C++17 | 1.5kb | 2024-02-24 22:31:58 | 2024-02-24 22:31:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int M = 5010;
int n, l[M], r[M];
bitset<M> vis, e[M];
int pl[M], pr[M], pre[M];
vector<int> vl, vr;
inline bool bfs(int n) {
queue<int> q;
q.push(n), vis.set();
while (!q.empty()) {
int p = q.front();
q.pop();
auto nw = vis & e[p];
for (int i = nw._Find_first(); i <= n; i = nw._Find_next(i)) {
vis.reset(i), pre[i] = p;
if (!pr[i]) {
while (i) pr[i] = pre[i], swap(i, pl[pre[i]]);
return true;
}
q.push(pr[i]);
}
}
return false;
}
inline int match() {
int ans = 0;
for (int i = 1; i <= n; i++) ans += bfs(i);
return ans;
}
int main() {
assert(scanf("%d", &n));
for (int i = 1; i <= n; i++)
assert(scanf("%d%d", l + i, r + i)), vl.push_back(l[i]), vr.push_back(r[i]);
auto mUnique = [](vector<int> &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
};
mUnique(vl), mUnique(vr);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
if (l[i] < l[j] && l[j] < r[i] && r[i] < r[j]) {
int pl = lower_bound(vl.begin(), vl.end(), l[j]) - vl.begin() + 1;
int pr = lower_bound(vr.begin(), vr.end(), r[i]) - vr.begin() + 1;
e[pl][pr] = 1;
}
printf("%d\n", 2 * n - match());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3780kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Wrong Answer
time: 72ms
memory: 6980kb
input:
5000 7985 7987 42 46 1591 1593 407 410 6305 6306 1456 1457 5874 5875 7135 7137 7041 7046 6813 6815 8868 8871 665 666 4055 4056 9789 9796 7067 7068 4745 4746 5167 5171 1735 1737 2125 2128 1444 1447 1348 1352 6087 6090 1381 1384 1600 1601 5187 5190 2801 2802 8449 8450 9376 9377 4021 4024 2674 2676 490...
output:
8149
result:
wrong answer 1st numbers differ - expected: '8134', found: '8149'