QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352488#7993. 哈密顿lexiyvvWA 304ms29188kbC++141.6kb2024-03-13 11:31:072024-03-13 11:31:08

Judging History

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

  • [2024-03-13 11:31:08]
  • 评测
  • 测评结果:WA
  • 用时:304ms
  • 内存:29188kb
  • [2024-03-13 11:31:07]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[100005],b[100005],ans;
set<pair<int,pair<int,int> > >s00,s01,s10,s11;
void ins(int x,int y){
//	cout<<"ins"<<x<<' '<<y<<endl;
	ans+=abs(a[x]-b[y]);
	s00.insert({-a[x]-b[y]-abs(a[x]-b[y]),{x,y}});
	s01.insert({-a[x]+b[y]-abs(a[x]-b[y]),{x,y}});
	s10.insert({a[x]-b[y]-abs(a[x]-b[y]),{x,y}});
	s11.insert({a[x]+b[y]-abs(a[x]-b[y]),{x,y}});
}
void del(int x,int y){
//	cout<<"del"<<x<<' '<<y<<endl;
	ans-=abs(a[x]-b[y]);
	s00.erase(s00.find({-a[x]-b[y]-abs(a[x]-b[y]),{x,y}}));
	s01.erase(s01.find({-a[x]+b[y]-abs(a[x]-b[y]),{x,y}}));
	s10.erase(s10.find({a[x]-b[y]-abs(a[x]-b[y]),{x,y}}));
	s11.erase(s11.find({a[x]+b[y]-abs(a[x]-b[y]),{x,y}}));
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i]>>b[i];
	ins(1,1);
	for(int i=2;i<=n;i++){
		int m00=(*s00.rbegin()).first+a[i]+b[i];pair<int,int>p00=(*s00.rbegin()).second;
		int m01=(*s01.rbegin()).first-a[i]+b[i];pair<int,int>p01=(*s01.rbegin()).second;
		int m10=(*s10.rbegin()).first+a[i]-b[i];pair<int,int>p10=(*s10.rbegin()).second;
		int m11=(*s11.rbegin()).first+a[i]-b[i];pair<int,int>p11=(*s11.rbegin()).second;
		int mx=max(max(m00,m01),max(m10,m11));
		if(m00==mx){
			del(p00.first,p00.second);
			ins(p00.first,i);ins(i,p00.second);
		}
		else if(m01==mx){
			del(p01.first,p01.second);
			ins(p01.first,i);ins(i,p01.second);
		}
		else if(m10==mx){
			del(p10.first,p10.second);
			ins(p10.first,i);ins(i,p10.second);
		}
		else if(m11==mx){
			del(p11.first,p11.second);
			ins(p11.first,i);ins(i,p11.second);
		}
	}
	cout<<ans<<endl;
	return 0;
}

詳細信息

Test #1:

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

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

2
732734236 669531729
368612323 916696032

output:

484881202

result:

ok single line: '484881202'

Test #3:

score: -100
Wrong Answer
time: 304ms
memory: 29188kb

input:

96739
960257511 790393830
766983782 374475134
476482176 529858300
310917487 76906076
81191659 653180897
119832756 362638666
228783015 626981197
74837554 781854003
663345706 153150021
576244413 708232220
842559077 417230462
249522463 815253339
391663517 742521049
60507117 258429449
112143256 81408991...

output:

48458500288501

result:

wrong answer 1st lines differ - expected: '48459768018811', found: '48458500288501'