QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95981 | #6308. Magic | zqs | WA | 96ms | 6360kb | C++14 | 1.2kb | 2023-04-12 19:38:25 | 2023-04-12 19:38:27 |
Judging History
answer
#include <cstdio>
#include <bitset>
#include <cstring>
inline int max(const int x, const int y) {return x > y ? x : y;}
std::bitset<5005> G[5005], vis, tmp;
int l[5005], r[5005], q[5005], lnk[5005], pre[5005], pv[5005], idl[10005], idr[10005], hd, tl;
bool isr[10005];
int main() {
int n; scanf("%d", &n);
for (int i = 1; i <= n; ++ i) scanf("%d%d", l + i, r + i), isr[r[i]] = true;
for (int i = 1, j = 0, k = 0; i <= 2 * n; ++ i)
if (!isr[i]) idl[i] = ++ j;
else idr[i] = ++ k;
for (int i = 1; i <= n; ++ i)
for (int j = 1; j <= n; ++ j) if (i != j && l[i] < l[j] && r[i] < r[j]) G[idr[r[i]]].set(idl[l[j]]);
int ans = 2 * n;
for (int i = 1; i <= n; ++ i) if (isr[i]) {
memset(pre, 0, sizeof pre);
vis.set(), q[hd = tl = 1] = i;
int flag = 0, p = 0;
while (hd <= tl) {
int u = q[hd ++];
tmp = G[u] & vis;
for (int i = tmp._Find_first(); i < 5005; i = tmp._Find_next(i))
if (!lnk[i]) {flag = i, p = u; break;}
else q[++ tl] = lnk[i], pre[lnk[i]] = u, pv[lnk[i]] = i, vis.flip(i);
}
if (flag) {
-- ans, lnk[flag] = p;
for (int j = p; j != i; j = pre[j]) lnk[pv[j]] = pre[j];
}
}
printf("%d", ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3108kb
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: 96ms
memory: 6360kb
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:
7502
result:
wrong answer 1st numbers differ - expected: '8134', found: '7502'