QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700016 | #6308. Magic | Idtwtei | TL | 0ms | 0kb | C++14 | 1.2kb | 2024-11-02 11:35:01 | 2024-11-02 11:35:02 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+100,INF=1e9;
#define gc getchar()
#define rd read()
inline int read(){
int x=0,f=0; char c=gc;
for(;c<'0'||c>'9';c=gc) f|=(c=='-');
for(;c>='0'&&c<='9';c=gc) x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
int n,s,t,l[N],r[N];
bitset<N*2> G[N*2];
int dis[N*2],q[N*2],ql,qr;
int bfs(){
for(int i=1;i<=t;++i) dis[i]=0; dis[q[ql=qr=1]=s]=1;
while(!ql<=qr){
int u=q[ql++];
for(int v=G[u]._Find_first();v<=t;v=max(v+1,(int)G[u]._Find_next(v))){
if(!dis[v]){
dis[v]=dis[u]+1,q[++qr]=v;
if(v==t) return 1;
}
}
}
return 0;
}
int dinic(int u,int df){
if(u==t) return df;
int res=df;
for(int v=G[u]._Find_first(),k;res&&v<=t;v=max(v+1,(int)G[u]._Find_next(v))){
if(dis[v]==dis[u]+1){
k=dinic(v,min(res,1));
if(!k) dis[v]=0;
else G[u][v]=0,G[v][u]=1,--res;
}
}
return df-res;
}
int main(){
n=rd,s=2*n+1,t=2*n+2;
for(int i=1;i<=n;++i) G[s][l[i]=rd]=1,G[r[i]=rd][t]=1;
for(int i=1;i<=n;++i) for(int j=1;j<=n;++j)
if(l[i]<l[j]&&l[j]<r[i]&&r[i]<r[j]) G[l[i]][r[j]]=1;
int dflow=0,maxflow=0;
while(bfs()) while(dflow=dinic(s,INF)) maxflow+=dflow;
printf("%d\n", 2*n-maxflow);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 3 6 7 1 9 5 10 4 8