QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751965 | #6308. Magic | lyx | WA | 76ms | 16320kb | C++14 | 1.5kb | 2024-11-15 21:25:51 | 2024-11-15 21:25:52 |
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,M=5005;
int n,l[M],r[M],S,T,cur[N],dis[N],Q[N],ans;
bitset<N>G[N];
inline void link(ri x,ri y){
G[x].set(y);G[y].set(x);
}
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(!G[x][y])break;
if(dis[y]==1e9){
dis[y]=dis[x]+1;
Q[++t]=y;
}
ri z=G[x]._Find_next(y);
y=max(y+1,z);
}
}
return dis[T]!=1e9;
}
inline int dfs(ri x,ri fw){
if(x==T||!fw)return fw;
ri res=0,y=G[x]._Find_first();
while(y<=T&&fw){
if(!G[x][y])break;
if(dis[y]==dis[x]+1){
ri Fw=dfs(y,1);
if(!Fw)dis[y]=1e9;
else{
G[x].flip(y);
G[y].flip(x);
res+=Fw;fw-=Fw;
}
}
ri z=G[x]._Find_next(y);
y=max(y+1,z);
}
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);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3932kb
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: 68ms
memory: 16320kb
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
Wrong Answer
time: 76ms
memory: 16272kb
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:
7079
result:
wrong answer 1st numbers differ - expected: '7047', found: '7079'