QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#556228#7993. 哈密顿wangjinghengWA 0ms15888kbC++201.6kb2024-09-10 16:02:532024-09-10 16:02:53

Judging History

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

  • [2024-09-10 16:02:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:15888kb
  • [2024-09-10 16:02:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200100;
pair<int,int> a[N],b[N];
array<int,3> c[N],w[N];
set<pair<int,int> >sa,sb;
int fa[N],vin[N],vout[N],vis[N];
int find(int x){
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
void merge(int x,int y){
	x=find(x),y=find(y);
	if(x==y) return;
	fa[x]=y;
}
void solve(){
	int n;cin>>n;
	int t=0;
	for(int i=1;i<=n;i++){
		fa[i]=i;
		int x;cin>>x;
		a[i]={x,i};
		c[++t]={x,i,0ll};
		cin>>x;
		b[i]={x,i};
		c[++t]={x,i,1ll};
	}
	sort(c+1,c+t+1);
	int res=0;
	for(int i=1;i<=t/2;i++){
		res-=c[i][0];
	}
	for(int i=t/2+1;i<=t;i++) res+=c[i][0];
	int ans=0,cnt=n;
	for(int i=1;i<=n;i++){
		if(c[i][2]==1){
			vin[c[i][1]]=1;
		}
	}
	for(int i=n+1;i<=n+n;i++){
		if(c[i][2]==0){
			vout[c[i][1]]=1;
		}
	}
	cnt=0;
	int ok=0,okk=0;
	for(int i=1;i<=n;i++){
		if(vin[i]+vout[i]==0) continue;
		if(vin[i]==1&&vout[i]==0) ok=1;
		if(vin[i]==0&&vout[i]==1) okk=1;
		if(vin[i]+vout[i]==2) cnt++,vis[i]=1;
	}
	if(ok&&okk||cnt==n){
		cout<<res<<"\n";return;
	}
	int tt=0,ll=1e13,rr=0;
	// for(int i=1;i<=n;i++){
	// 	if(vis[i]){
	// 		w[++tt]={a[i].first,a[i].second,0};w[++tt]={b[i].first,b[i].second,1};
	// 	}
	// }
	// sort(w+1,w+tt+1);
			int u2=c[n-1][0],u1=c[n][0],v1=c[n+1][0],v2=c[n+2][0];
			// cout<<u2<<" "<<u1<<" "<<v1<<" "<<v2;
			// if(c[n][1]!=c[n+1][1]){
				res-=2*(v1-u1);
			// }
			// else{
			// 	int minx=1e13;
			// 	minx=min(v1-u2,v2-u1);
			// 	res-=2*minx;
			// }


	cout<<res<<"\n";

}

signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
	solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 15888kb

input:

3
1 10
8 2
4 5

output:

14

result:

wrong answer 1st lines differ - expected: '10', found: '14'