QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#446820#6308. Magicjames1BadCreeperTL 0ms0kbC++171.4kb2024-06-17 16:37:512024-06-17 16:37:51

Judging History

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

  • [2024-06-17 16:37:51]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-17 16:37:51]
  • 提交

answer

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

int n, S, T, d[N]; 
bitset<N> g[N]; 

int bfs(void) {
    memset(d, -1, sizeof d); d[S] = 1; 
    queue<int> q; q.push(S); 
    while (!q.empty()) {
        int u = q.front(); q.pop(); 
        for (int v = g[u]._Find_first(); v != g[u].size(); v = g[u]._Find_next(v))
            if (d[v] == -1) d[v] = d[u] + 1, q.push(v); 
    }
    return d[T]; 
}
int dinic(int u, int res) {
    if (u == T) return res; 
    int flow = 0;
    for (int v = g[u]._Find_first(); v != g[u].size() && res; v = g[u]._Find_next(v)) {
        if (d[v] == d[u] + 1) {
            int k = dinic(v, min(res, 1)); 
            flow += k, res -= k; 
            if (k) g[u][v] = 0, g[v][u] = 1; 
        }
    }
    if (!flow) d[u] = -1; 
    return flow;
}

int l[N], r[N], pos[N]; 

int main(void) {    
    ios::sync_with_stdio(0); 

    cin >> n; S = 0, T = 2 * n + 1;
    for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i], pos[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])
                g[l[j]][r[i]] = 1;
    for (int i = 1; i <= 2 * n; ++i)
        if (pos[i] == 1) g[S][i] = 1; 
        else g[i][T] = 1; 
    int ans = 2 * n; 
    while (bfs()) ans -= dinic(S, 1e9); 
    cout << ans << "\n"; 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

5
2 3
6 7
1 9
5 10
4 8

output:


result: