QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446852 | #6308. Magic | james1BadCreeper | WA | 74ms | 16204kb | C++17 | 1.6kb | 2024-06-17 16:55:31 | 2024-06-17 16:55:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n;
int l[N], r[N], lft[N];
bitset<N> E[N];
int S, T, vis[N];
int cur[N], d[N];
int bfs(void) {
memset(d, -1, sizeof d);
queue<int> q; q.push(S); d[S] = 1;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v = E[u]._Find_first(); v != E[u].size(); v = E[u]._Find_next(v))
if (d[v] == -1) {
d[v] = d[u] + 1; q.push(v);
if (v == T) return 1;
}
}
return 0;
}
int dinic(int x, int res) {
if (x == T) return res;
int flow = 0; // vis[x] = 1;
for (int y = E[x]._Find_first(); y != E[x].size() && res; y = E[x]._Find_next(y)) {
// cur[x] = y;
// int c = min(res, 1);
if (!vis[y] && d[y] == d[x] + 1) {
int k = dinic(y, min(res, 1)); flow += k; res -= k;
if (k) E[x][y] = 0; E[y][x] = 1;
}
}
if (!flow) d[x] = -1; // vis[x] = 0;
return flow;
}
int main(void) {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n; S = 0; T = n * 2 + 1;
for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i], lft[l[i]] = 1;
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])
E[l[j]][r[i]] = 1;
for (int i = 1; i <= n * 2; ++i)
if (lft[i] == 1) E[S][i] = 1;
else E[i][T] = 1;
// for (int i = S; i <= T; ++i) cur[i] = E[i]._Find_first();
int ans = n * 2;
while (bfs()) ans -= dinic(S, 1e9);
cout << ans << "\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3884kb
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: 70ms
memory: 16204kb
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
Wrong Answer
time: 74ms
memory: 16172kb
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...
output:
7036
result:
wrong answer 1st numbers differ - expected: '7047', found: '7036'