QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99025#6308. MagicAcestarWA 14ms15476kbC++141.4kb2023-04-21 08:57:412023-04-21 08:57:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 08:57:43]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:15476kb
  • [2023-04-21 08:57:41]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 5005;

int n;
pair<int, int> a[N];
bitset<N << 1> g[N << 1];
int s, t;
int dep[N << 1];

bool bfs()
{
    memset(dep, 0, sizeof(dep));
    queue<int> que;
    dep[s] = 1, que.push(s);
    while(!que.empty())
    {
        int u = que.front(); que.pop();
        for(auto v = g[u]._Find_first(); v <= t; v = g[u]._Find_next(v))
            if(!dep[v]) dep[v] = dep[u] + 1, que.push(v);
    }
    return dep[t];
}

int dfs(int u, int in)
{
    if(u == t || !in) return in;
    int out = 0;
    for(auto v  = g[u]._Find_first(); v <= t; v = g[u]._Find_next(v))
    {
        if(dep[v] != dep[u] + 1) continue;
        int f = dfs(v, min(in, 1));
        if(f) g[u][v] = 0, g[v][u] = 1;
        in -= f, out += f;
        if(!in) break;
    }
    return out;
}

int dinic()
{
    int res = 0;
    while(bfs()) res += dfs(s, 1e9);
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    cin >> n; s = 2 * n + 1, t = s + 1;
    for(int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++)
            if(a[j].first < a[i].second && a[i].second < a[j].second)
                g[j][n + 1] = 1;
    for(int i = 1; i <= n; i++) g[s][i] = 1, g[n + i][t] = 1;

    cout << 2 * n - dinic() << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3432kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 14ms
memory: 15476kb

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:

9999

result:

wrong answer 1st numbers differ - expected: '8134', found: '9999'