QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269948#6308. MagicrobinyqcWA 53ms6624kbC++171.4kb2023-11-30 12:02:332023-11-30 12:02:33

Judging History

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

  • [2023-11-30 12:02:33]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:6624kb
  • [2023-11-30 12:02:33]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std;

const int N = 5008;

int n, m;
int l[N], r[N];
bitset<N> g[N], nw, vis;
int pre[N], pl[N], pr[N];
int q[N + N], hd, tl;
int ln[N], rn[N];

bool bfs(int s)
{
    hd = tl = 0;
    q[++tl] = s;
    pre[s] = 0;
    vis.set();
    while (hd < tl) {
        int x = q[++hd];
        nw = vis & g[x];
        for (int i = nw._Find_first(); i <= n; i = nw._Find_next(i)) {
        // for (int i = 1; i <= n; i++) if (nw[i]) {
            vis.reset(i);
            pre[i] = x;
            if (!pr[i]) {
                while (i) {
                    pr[i] = pre[i];
                    swap(i, pl[pre[i]]);
                }
                return 1;
            }
            q[++tl] = pr[i];
        }
    }
    return 0;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
    cin >> n, m = n + n;
    for (int i = 1; i <= n; i++) {
        cin >> l[i] >> r[i];
        ln[l[i]] = i, rn[r[i]] = i;
    }
    for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
        if (l[i] < l[j] && r[i] < r[j] && r[i] > l[j]) {
            g[rn[r[i]]].set(ln[l[j]]);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) ans += bfs(i);
    cout << m - ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3428kb

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: 53ms
memory: 6624kb

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:

8260

result:

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