QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751985 | #6308. Magic | lyx | WA | 77ms | 16316kb | C++14 | 1.4kb | 2024-11-15 21:29:05 | 2024-11-15 21:29:06 |
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(dis[y]==1e9){
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&&G[x][y]){
ri Fw=dfs(y,1);
if(!Fw)dis[y]=1e9;
else{
G[x][y]=0;G[y][x]=1;
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);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3944kb
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: 16316kb
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: 77ms
memory: 16316kb
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:
6984
result:
wrong answer 1st numbers differ - expected: '7047', found: '6984'