QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#99196#6308. Magicice_cupWA 78ms5640kbC++141.5kb2023-04-21 16:43:372023-04-21 16:43:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 16:43:40]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:5640kb
  • [2023-04-21 16:43:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int head[10010],to[300100],nxt[300100],v[300100],cnt=1,n,ask[10010],mt[10010],s,t;
int cur[10010],vis[10010],d[10010],inf=0x3f3f3f3f;
struct node{
	int l,r;
}a[5010];
void add(int u,int e,int val){
	nxt[++cnt]=head[u];
	to[cnt]=e;
	v[cnt]=val;
	head[u]=cnt;
}
bool bfs(){
	queue<int>q;
	q.push(s);
	memset(d,0,sizeof(d));
	d[s]=1;
	cur[s]=head[s];
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=nxt[i]){
			if(!d[to[i]]&&v[i]>0){
				d[to[i]]=d[u]+1;
				cur[to[i]]=head[to[i]];
				if(to[i]==t){
					return 1;
				}
				q.push(to[i]);
			}
		}
	}
	return 0;
}
int dfs(int u,int re){
	if(u==t||re<=0){
		return re;
	}
	int tmp=re;//cout<<cur[u];
	for(int &i=cur[u];i;i=nxt[i]){
//		if(v[i]>0)cout<<v[i]<<' ';
		if(v[i]>0&&d[to[i]]==d[u]+1){
			int tm=dfs(to[i],min(v[i],tmp));//wrong*1 tmp错写成 re 
			if(tm<=0){
				d[to[i]]=0;
			}
			tmp-=tm;
			v[i]-=tm;
			v[i^1]+=tm;
			if(tmp<=0){
				break;
			}
		}
	}
//	if(tmp<0)cout<<re<<' '<<tmp<<endl;
	return re-tmp;
}
void dinic(){
	int ans=2*n;
	while(bfs()){ 
		int tmp=dfs(s,inf);
		if(tmp>=0)ans-=tmp;
	}
	cout<<ans;
}
int main(){
	cin>>n;
	s=0;
	t=2*n+1;
	for(int i=1;i<=n;i++){
		cin>>a[i].l>>a[i].r;
		add(s,a[i].l,1);
		add(a[i].r,t,1);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			if(a[i].l<a[j].l&&a[j].l<a[i].r&&a[i].r<a[j].r){
				add(a[j].l,a[i].r,1);
			}
		}
	}
	dinic();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 3
6 7
1 9
5 10
4 8

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 78ms
memory: 5640kb

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:

7468

result:

wrong answer 1st numbers differ - expected: '8134', found: '7468'