QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#301938#7993. 哈密顿PhantomThreshold#WA 1ms3456kbC++201.0kb2024-01-10 14:39:192024-01-10 14:39:20

Judging History

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

  • [2024-01-10 14:39:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3456kb
  • [2024-01-10 14:39:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll INF=1e18;

const int maxn=100000;
int n;
ll a[maxn+50];
ll b[maxn+50];

int main(){
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i] >> b[i];
	
	ll sum=0;
	vector<pair<ll,ll>> v;
	for (int i=1;i<=n;i++){
		v.emplace_back(a[i],(ll)i);
		v.emplace_back(b[i],(ll)i);
		sum+=a[i]+b[i];
	}
	sort(v.begin(),v.end());
	
	ll mxsum=0;
	for (int i=n;i<n+n;i++) mxsum+=v[i].first;
	
	vector<int> vis(n+5);
	for (int i=n;i<n+n;i++){
		if (vis[v[i].second]){
			cout << mxsum+mxsum-sum << "\n";
			return 0;
		}
		vis[v[i].second]=1;
	}
	
	ll mid=v[n].first;
	for (int i=1;i<=n;i++) if (a[i]>=mid) swap(a[i],b[i]);
	
	vector<ll> premx(n+5),sufmx(n+5);
	for (int i=1;i<=n;i++) premx[i]=max(premx[i-1],a[i]);
	for (int i=n;i>=1;i--) sufmx[i]=min(sufmx[i+1],a[i]);
	
	ll mx=-INF;
	for (int i=1;i<=n;i++) mx=max(mx,-b[i]+max(premx[i-1],sufmx[i+1]));
	
	cout << (mxsum+mx)*2-sum << "\n";
	 
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3456kb

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3456kb

input:

2
732734236 669531729
368612323 916696032

output:

116957610

result:

wrong answer 1st lines differ - expected: '484881202', found: '116957610'