QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#95983 | #6308. Magic | zqs | TL | 79ms | 6300kb | C++14 | 1.1kb | 2023-04-12 19:46:21 | 2023-04-12 19:46:25 |
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] && l[j] < r[i] && r[i] < r[j]) G[idr[r[i]]].set(idl[l[j]]);
int ans = 2 * n;
for (int i = 1; i <= n; ++ i) {
memset(pre, 0, sizeof pre);
vis.set(), q[hd = tl = 1] = i;
int 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]) {lnk[i] = p = u; break;}
else q[++ tl] = lnk[i], pre[lnk[i]] = u, pv[lnk[i]] = i, vis.flip(i);
}
if (p) {
-- ans;
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: 1ms
memory: 3052kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 79ms
memory: 6300kb
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:
8134
result:
ok 1 number(s): "8134"
Test #3:
score: -100
Time Limit Exceeded
input:
5000 3171 3172 4062 4064 4647 4651 3670 3673 7112 7114 9714 9717 3781 3789 8422 8426 457 460 5450 5454 7113 7122 6313 6320 9969 9973 828 832 6878 6892 4476 4483 892 903 251 259 6304 6315 130 134 9206 9215 2679 2686 9090 9091 8222 8228 9374 9375 2985 2989 3397 3401 4916 4918 6819 6821 883 889 2516 25...