QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#530755#6308. MagicpropaneTL 9ms6636kbC++201.7kb2024-08-24 17:09:502024-08-24 17:09:50

Judging History

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

  • [2024-08-24 17:09:50]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:6636kb
  • [2024-08-24 17:09:50]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<bitset>
#include<queue>
#include<algorithm>
using namespace std;
using LL = long long;
const int N = 5000;
bitset<N> g[5005];
int match[5005], pre[5005];

bool bfs(int st){
    queue<int> q;
    q.push(st);
    bitset<N> v;
    v.set();
    memset(pre, -1, sizeof pre);
    while(!q.empty()){
        int t = q.front();
        q.pop();
        auto bs = v & g[t];
        for(auto i = bs._Find_first(); i != bs.size(); i = bs._Find_next(i)){
            pre[i + N] = t;
            if (match[i] != -1){
                v.reset(i);
                pre[match[i]] = i;
                q.push(match[i]);
            }
            else{
                for(auto j = i; ; j = pre[pre[j + N]]){
                    match[j] = pre[j + N];
                    if (pre[j + N] == st) break;
                }
                return true;
            }
        }
    }
    return false;
}

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<pair<int, int> > p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    for(int i = 0; i < n; i++){
        auto [l1, r1] = p[i];
        for(int j = i + 1; j < n; j++){
            auto [l2, r2] = p[j];
            if (r1 > l2 and r1 < r2){
                g[i].set(j);
            }
        }
    }
    memset(match, -1, sizeof match);
    int cnt = 0;
    for(int i = 0; i < n; i++){
        cnt += bfs(i);
    }
    cout << 2 * n - cnt << '\n';

}

詳細信息

Test #1:

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

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 9ms
memory: 6636kb

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:

8134

result:

ok 1 number(s): "8134"

Test #3:

score: -100
Time Limit Exceeded

input:

5000
3171 3172
4062 4064
4647 4651
3670 3673
7112 7114
9714 9717
3781 3789
8422 8426
457 460
5450 5454
7113 7122
6313 6320
9969 9973
828 832
6878 6892
4476 4483
892 903
251 259
6304 6315
130 134
9206 9215
2679 2686
9090 9091
8222 8228
9374 9375
2985 2989
3397 3401
4916 4918
6819 6821
883 889
2516 25...

output:


result: