QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446762#6308. Magicjames1BadCreeperWA 71ms16084kbC++171.6kb2024-06-17 15:55:372024-06-17 15:55:38

Judging History

你现在查看的是最新测评结果

  • [2024-06-17 15:55:38]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:16084kb
  • [2024-06-17 15:55:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5; 

int n; 
int l[N], r[N]; 
bool lft[N]; 
bitset<N> E[N]; 
int S, T, vis[N]; 
int cur[N], d[N]; 

bool bfs(void) {
    memset(cur, 0, sizeof cur); 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(); y = E[x]._Find_next(y)) {
        // cur[x] = y; 
        int c = min(res, 1); 
        if (!vis[y] && d[y] == d[x] + 1 && c) {
            int k = dinic(y, c); flow += k; res -= 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; 
    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; 
    S = 0; T = n * 2 + 1; 
    for (int i = 1; i <= n * 2; ++i)
        if (lft[i]) 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: 0ms
memory: 3904kb

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: 66ms
memory: 16012kb

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: 71ms
memory: 16084kb

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:

7171

result:

wrong answer 1st numbers differ - expected: '7047', found: '7171'