QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111678#6308. MagicDiuRE 2ms5720kbC++141.3kb2023-06-07 21:10:522023-06-07 21:10:53

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 21:10:53]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:5720kb
  • [2023-06-07 21:10:52]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010,M=1e7+1e4+10,Inf=1e8;
int n,s,t;
struct edge{
	int v,w,nxt;
}e[M];
int hd[N],tot=1;
void add(int u,int v,int w){e[++tot]={v,w,hd[u]},hd[u]=tot;}
void Add(int u,int v,int w){add(u,v,w),add(v,u,0);}
int lev[N];
bool bfs(int s,int t){
	memset(lev,-1,(t+2)*sizeof(int));
	lev[s]=1;queue<int> q;while(!q.empty())q.pop();
	q.push(s);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=hd[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(e[i].w&&lev[v]==-1)lev[v]=lev[u]+1,q.push(v);
		}
	}
	return lev[t]!=-1;
}
int dfs(int u,int in){
	if(u==t)return in;
	int out=0;
	for(int i=hd[u];i;i=e[i].nxt){
		int v=e[i].v;
		if(e[i].w&&lev[v]==lev[u]+1){
			int use=dfs(v,min(e[i].w,in));
			e[i].w-=use,out+=use;
			e[i^1].w+=use,in-=use;
			if(!in)break;
		}
	}
	if(!out)lev[u]=-1;
	return out;
}
int l[N],r[N];
signed main(){
	scanf("%d",&n),s=2*n+1,t=s+1;
	for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(l[i]<l[j]&&l[j]<r[i]&&r[i]<r[j])Add(r[i],l[j],1);
			if(l[j]<l[i]&&l[i]<r[j]&&r[j]<r[i])Add(r[j],l[i],1);
		}
	}
	for(int i=1;i<=n;i++)Add(s,r[i],1),Add(l[i],t,1);
	int ans=2*n;
	while(bfs(s,t))ans-=dfs(s,Inf);
	printf("%d\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5720kb

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Dangerous Syscalls

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:


result: