QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#446781#6308. Magicjames1BadCreeperWA 1ms3748kbC++171.7kb2024-06-17 16:10:282024-06-17 16:10:28

Judging History

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

  • [2024-06-17 16:10:28]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3748kb
  • [2024-06-17 16:10:28]
  • 提交

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 <= T; y = max(y + 1, int(E[x]._Find_next(y)))) {
        // cur[x] = y; 
        // assert(E[x][y] == 1); 
        int c = min(res, 1); 
        if (d[y] == d[x] + 1 && c) {
            int k = dinic(y, c); 
            // if (!k) d[y] = -1; 
            flow += k; res -= k; 
            E[x][y] = 0; E[y][x] = 1; 
        }
    }
    if (!flow) d[x] = -1; 
    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: 0
Wrong Answer
time: 1ms
memory: 3748kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

10

result:

wrong answer 1st numbers differ - expected: '9', found: '10'