QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#699936 | #6308. Magic | Idtwtei | ML | 0ms | 3880kb | C++14 | 1.3kb | 2024-11-02 11:18:31 | 2024-11-02 11:18:32 |
Judging History
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]; queue<int> q;
int bfs(){
for(int i=1;i<=t;++i) dis[i]=0;
while(!q.empty()) q.pop(); q.push(s),dis[s]=1;
while(!q.empty()){
int u=q.front(); q.pop();
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.push(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(i!=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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
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