QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602204#9427. Collect the Coinsucup-team3282RE 0ms0kbC++141.2kb2024-09-30 20:59:502024-09-30 20:59:50

Judging History

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

  • [2024-11-06 15:56:27]
  • hack成功,自动添加数据
  • (/hack/1139)
  • [2024-09-30 20:59:50]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-30 20:59:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+10;

int T;
int n;
int t[maxn],c[maxn];

bool f(int i,int j,int v){
	if(j>=i)
		return 1;
	return (ll)v*(t[i]-t[j])>=abs(c[i]-c[j]);
}

bool check(int v){
	vector<int> il,ir;
	for(int i=2;i<=n;i++){
		if(!f(i,i-1,v)){
			if(c[i]>c[i-1]){
				il.push_back(i-1);
				ir.push_back(i);
			}
			else{
				il.push_back(i);
				ir.push_back(i-1);
			}
		}
	}
//	cout<<"v: "<<v<<endl;for(int i:il)cout<<i<<endl;cout<<endl;for(int i:ir)cout<<i<<endl;cout<<endl;
	il.resize(unique(il.begin(),il.end())-il.begin());
	ir.resize(unique(ir.begin(),ir.end())-ir.begin());
	int pl=0,pr=0;
	for(int i=1;i<=n;i++){
		if(pl+2<il.size()&&il[pl+1]<=i)
			pl++;
		if(pr+2<ir.size()&&ir[pr+1]<=i)
			pr++;
		if(!( (f(i,il[pl],v)&&f(il[pl+1],i,v)) || (f(i,ir[pr],v)&&f(ir[pr+1],i,v)) ))
			return 0;
	}
	return 1;
}

int main(){
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--){
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>t[i]>>c[i];
		
		int l=0,r=1e9,mid,ans=-1;
		while(l<=r){
			mid=(l+r)>>1;
			if(check(mid)){
				ans=mid;
				r=mid-1;
			}
			else{
				l=mid+1;
			}
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3
5
1 1
3 7
3 4
4 3
5 10
1
10 100
3
10 100
10 1000
10 10000

output:

500000000

result: