QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751884 | #6308. Magic | lyx | ML | 1ms | 5924kb | C++14 | 1.4kb | 2024-11-15 21:10:53 | 2024-11-15 21:10:54 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define ull unsigned ll
#define ri register int
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=10015;
int n,l[N],r[N],S,T,cur[N],dis[N],Q[N],ans;
bitset<N>G[N],E[N];
inline void link(ri x,ri y){
G[x].set(y);G[y].set(x);
E[x].set(y);
}
inline int bfs(){
ri h=0,t=1;Q[1]=S;
fo(i,1,T)dis[i]=1e9;
dis[S]=0;
while(h<t){
ri x=Q[++h],y=G[x]._Find_first();
while(y<=T){
if(dis[y]==1e9&&E[x][y]){
dis[y]=dis[x]+1;
Q[++t]=y;
}
y=G[x]._Find_next(y);
}
}
return dis[T]!=1e9;
}
inline int dfs(ri x,ri fw){
if(x==T||!fw)return fw;
ri res=0,y=cur[x];
while(y<=T&&fw){
if(dis[y]==dis[x]+1&&E[x][y]){
ri Fw=dfs(y,1);
if(!Fw)dis[y]=1e9;
else{
E[x].flip(y);
E[y].flip(x);
res+=Fw;fw-=Fw;
}
}
y=G[x]._Find_next(y);
}
cur[x]=y;
return res;
}
int main(){
scanf("%d",&n);
S=2*n+1;T=S+1;
fo(i,1,n){
scanf("%d%d",&l[i],&r[i]);
link(S,l[i]);link(r[i],T);
}
fo(i,1,n)fo(j,1,n){
if(l[i]<l[j]&&r[i]<r[j]&&l[j]<r[i])link(l[j],r[i]);
}
while(bfs()){
ri fw=0;
fo(i,1,T)cur[i]=G[i]._Find_first();
while(fw=dfs(S,1e9))ans+=fw;
}
printf("%d",2*n-ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5924kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: -100
Memory 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:
8134