QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106389 | #6308. Magic | bear0131 | RE | 33ms | 10348kb | C++11 | 2.8kb | 2023-05-17 16:18:36 | 2023-05-17 16:18:39 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int inf = 0x3f3f3f3f;
int n;
array<int, 2> a[5050];
int cn = 0;
namespace mf{
int hd[250250], cur[250250], dis[250250];
int to[250250], cap[250250], nxt[250250], ce = 0;
void clr(){
memset(hd, -1, sizeof(hd));
}
void ae(int f, int t, int c){
//cout << "ae " << f << " " << t << " " << c << endl;
nxt[ce] = hd[f], to[ce] = t, cap[ce] = c, hd[f] = ce++;
nxt[ce] = hd[t], to[ce] = f, cap[ce] = 0, hd[t] = ce++;
}
bool bfs(int S, int T){
fill(dis, dis+cn, inf);
static int q[250250];
int qhd = 0, qrr = 0;
q[qrr++] = S, dis[S] = 0;
while(qhd < qrr){
int u = q[qhd++];
for(int e = hd[u]; e >= 0; e = nxt[e]){
if(!cap[e]) continue;
int t = to[e];
if(dis[t] > dis[u] + 1){
dis[t] = dis[u] + 1;
q[qrr++] = t;
}
}
}
return dis[T] < inf;
}
int dfs(int u, int dest, int f){
if(u == dest) return f;
int nf = 0;
for(int &e = cur[u]; e >= 0; e = nxt[e]){
int t = to[e];
if(!cap[e] || dis[t] != dis[u] + 1) continue;
int ret = dfs(t, dest, min(f, cap[e]));
nf += ret, cap[e] -= ret, cap[e^1] += ret;
if(nf == f) break;
}
return nf;
}
int mf(int S, int T){
int ret = 0;
while(bfs(S, T)){
rep(i, cn) cur[i] = hd[i];
ret += dfs(S, T, inf);
}
return ret;
}
}
int nid[40040];
int upd(int p, int l, int r, int u){
nid[u] = cn++;
//cout << "upd " << p << " " << l << " " << r << " " << u << ": " << nid[u] << endl;
if(l == r)
return nid[u];
int mid = (l+r) >> 1, ret;
if(p <= mid){
ret = upd(p, l, mid, u+u);
} else {
ret = upd(p, mid+1, r, u+u+1);
}
if(nid[u+u] >= 0) mf::ae(nid[u], nid[u+u], inf);
if(nid[u+u+1] >= 0) mf::ae(nid[u], nid[u+u+1], inf);
return ret;
}
void segae(int f, int tl, int tr, int l, int r, int u){
//cout << "segae " << f << " " << tl << " " << tr << " " << l << " " << r << " " << u << ": " << nid[u] << endl;
if(nid[u] < 0 || tl > r || l > tr) return ;
if(tl <= l && r <= tr) return mf::ae(f, nid[u], 1);
int mid = (l+r) >> 1;
segae(f, tl, tr, l, mid, u+u), segae(f, tl, tr, mid+1, r, u+u+1);
}
int main(){
ios::sync_with_stdio(false);
cin >> n;
rep(i, n)
cin >> a[i][0] >> a[i][1], --a[i][0], --a[i][1];
sort(a, a+n);
memset(nid, -1, sizeof(nid));
mf::clr();
cn = 2;
rep(i, n){
//cout << "-----------" << i << ": " << a[i][0] << " " << a[i][1] << "-----------------" << endl;
mf::ae(upd(a[i][1], 0, 2*n-1, 1), 1, 1);
mf::ae(0, cn, 1);
segae(cn, a[i][0]+1, a[i][1]-1, 0, 2*n-1, 1);
++cn;
}
cout << 2*n - mf::mf(0, 1) << "\n";
return 0;
}
// by zxb
// start coding at 15:32
// submission #1 at 16:14
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 9684kb
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: 10ms
memory: 10112kb
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: 0
Accepted
time: 21ms
memory: 9440kb
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:
7047
result:
ok 1 number(s): "7047"
Test #4:
score: 0
Accepted
time: 33ms
memory: 10348kb
input:
5000 7269 7286 1979 1990 4225 4241 7866 7872 2052 2067 1508 1514 2366 2370 3488 3493 8979 8987 302 306 6730 6732 7704 7705 5528 5544 7420 7425 4705 4712 593 601 6662 6668 5228 5257 2008 2013 548 562 7949 7950 1017 1020 1025 1028 6 11 4722 4736 9945 9950 8368 8379 6781 6787 4558 4566 400 404 858 864 ...
output:
6191
result:
ok 1 number(s): "6191"
Test #5:
score: -100
Runtime Error
input:
5000 3005 3008 7811 7821 2832 2840 9812 9818 3947 3952 3629 3665 7443 7455 1473 1478 1467 1494 5499 5508 229 232 9477 9498 9500 9514 4769 4775 9488 9503 1514 1520 5101 5112 2455 2456 3558 3610 9072 9188 659 666 2286 2301 9735 9782 5959 5984 5823 5844 1827 1835 3658 3681 3494 3503 1016 1018 3418 3420...