QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#498833#6308. Magiccz_yxxTL 0ms4024kbC++201.9kb2024-07-30 20:26:032024-07-30 20:26:03

Judging History

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

  • [2024-07-30 20:26:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:4024kb
  • [2024-07-30 20:26:03]
  • 提交

answer

// sis puella oier
#include <bits/stdc++.h>
using namespace std;
// #define int long long
// typedef long long ll;
int read(){
    int xx = 0, f = 1; char ch = getchar();
    for (;!isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (; isdigit(ch); ch = getchar())
        xx = (xx << 3) + (xx << 1) + ch - '0';
    return xx * f;
}
const int N = 10002, inf = 1e9 + 7;
int tot, s, t;
bitset <N> e[N];
int d[N];
bool bfs(){
    for (int i = 1; i <= tot; ++i)d[i] = -1;
    d[s] = 0; queue <int> q; q.push(s);
    int x;
    while(!q.empty()){
        x = q.front(); q.pop();
        for (int v = e[x]._Find_first(); v <= tot; v = e[x]._Find_next(v)){
            if (d[v] == -1 && e[x][v] > 0){
                d[v] = d[x] + 1;
                if (v == t)return true;
                q.push(v);
            }
        }
    }
    return false;
}
int dfs(int x, int lim){
    if (x == t)return lim;
    int flow = 0, ret;
    for (int v = e[x]._Find_first(); v <= tot; v = e[x]._Find_next(v)){
        if (d[v] == d[x] + 1 && e[x][v] > 0){
            ret = dfs(v, min(lim - flow, 1));
            if (ret <= 0)d[v] = -1;
            e[x][v] = 0, e[v][x] = 1, flow += ret;
        }
    }
    return flow;
}
int dinic(){
    int ret = 0, flow;
    while(bfs())while(flow = dfs(s, inf))ret += flow;
    return ret;
}
int n, l[N], r[N], fl[N];
signed main(){
    n = read(), tot = n + n + 2, s = n + n + 1, t = n + n + 2;
    for (int i = 1; i <= n; ++i)l[i] = read(), r[i] = read(),
    fl[l[i]] = -1, fl[r[i]] = 1;
    for (int i = 1; i <= n; ++i)for (int j = i; 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 + n; ++i)if (fl[i] == -1)e[s][i] = 1;
    for (int j = 1; j <= n + n; ++j)if (fl[j] == 1)e[j][t] = 1;
    int ans = n + n - dinic();
    printf("%d\n", ans);
    return 0;
}


詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4024kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Time Limit Exceeded

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:


result: