QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#602516#9427. Collect the Coinsucup-team3282Compile Error//C++143.1kb2024-10-01 10:01:002024-10-01 10:01:02

Judging History

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

  • [2024-11-06 15:56:27]
  • hack成功,自动添加数据
  • (/hack/1139)
  • [2024-10-01 10:01:02]
  • 评测
  • [2024-10-01 10:01:00]
  • 提交

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> b(n);
	vector<int> il,ir;
	for(int i=2;i<=n;i++){
		if(!f(i,i-1,v)){
			if(c[i]>c[i-1]){
				if(b[i-1]==2||b[i]==1)
					return 0;
				b[i-1]=1;b[i]=2;
				il.push_back(i-1);
				ir.push_back(i);
			}
			else{
				if(b[i-1]==1||b[i]==2)
					return 0;
				b[i]=1;b[i-1]=2;
				il.push_back(i);
				ir.push_back(i-1);
			}
		}
	}
	il.resize(unique(il.begin(),il.end())-il.begin());
	ir.resize(unique(ir.begin(),ir.end())-ir.begin());
//	cout<<"v: "<<v<<endl;for(int i:il)cout<<i<<' ';cout<<endl;for(int i:ir)cout<<i<<' ';cout<<endl;
	if(il.empty())
		return 1;
	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++;
//		cout<<i<<' '<<il[pl]<<' '<<il[pl+1]<<' '<<ir[pr]<<' '<<ir[pr+1]<<endl;
		bool f1=0,f2=0;
		
		if(il.size()==1)
			f1=1;
		else{
			if(i<il[pl]||i>il[pl+1])
				f1=1;
			else{
				if(f(i,il[pl],v)&&f(il[pl+1],i,v))
					f1=1;
			}
		}
		if(ir.size()==1)
			f2=1;
		else{
			if(i<ir[pr]||i>ir[pr+1])
				f2=1;
			else{
				if(f(i,ir[pr],v)&&f(ir[pr+1],i,v))
					f2=1;
			}
		}
		if(!f1&&!f2)
			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;
}#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);
			}
		}
	}
	il.resize(unique(il.begin(),il.end())-il.begin());
	ir.resize(unique(ir.begin(),ir.end())-ir.begin());
//	cout<<"v: "<<v<<endl;for(int i:il)cout<<i<<' ';cout<<endl;for(int i:ir)cout<<i<<' ';cout<<endl;
	if(il.empty())
		return 1;
	il.push_back(0);
	ir.push_back(0);
	int pl=0,pr=0;
	for(int i=1;i<=n;i++){
		if(pl+2<il.size()-1&&il[pl+1]<i)
			pl++;
		if(pr+2<ir.size()-1&&ir[pr+1]<i)
			pr++;
//		cout<<i<<' '<<il[pl]<<' '<<il[pl+1]<<' '<<ir[pr]<<' '<<ir[pr+1]<<endl;
		if(il[pl+1]<i&&ir[pr+1]<i)
			break;
		if(!( (f(i,il[pl],v)&&(il[pl+1]>=i&&f(il[pl+1],i,v))) || (f(i,ir[pr],v)&&ir[pr+1]>=i&&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;
}

詳細信息

answer.code:101:2: error: stray ‘#’ in program
  101 | }#include <bits/stdc++.h>
      |  ^
answer.code:101:3: error: ‘include’ does not name a type
  101 | }#include <bits/stdc++.h>
      |   ^~~~~~~
answer.code:104:11: error: redefinition of ‘const int maxn’
  104 | const int maxn=1e6+10;
      |           ^~~~
answer.code:4:11: note: ‘const int maxn’ previously defined here
    4 | const int maxn=1e6+10;
      |           ^~~~
answer.code:106:5: error: redefinition of ‘int T’
  106 | int T;
      |     ^
answer.code:6:5: note: ‘int T’ previously declared here
    6 | int T;
      |     ^
answer.code:107:5: error: redefinition of ‘int n’
  107 | int n;
      |     ^
answer.code:7:5: note: ‘int n’ previously declared here
    7 | int n;
      |     ^
answer.code:108:5: error: redefinition of ‘int t [1000010]’
  108 | int t[maxn],c[maxn];
      |     ^
answer.code:8:5: note: ‘int t [1000010]’ previously declared here
    8 | int t[maxn],c[maxn];
      |     ^
answer.code:108:13: error: redefinition of ‘int c [1000010]’
  108 | int t[maxn],c[maxn];
      |             ^
answer.code:8:13: note: ‘int c [1000010]’ previously declared here
    8 | int t[maxn],c[maxn];
      |             ^
answer.code:110:6: error: redefinition of ‘bool f(int, int, int)’
  110 | bool f(int i,int j,int v){
      |      ^
answer.code:10:6: note: ‘bool f(int, int, int)’ previously defined here
   10 | bool f(int i,int j,int v){
      |      ^
answer.code:116:6: error: redefinition of ‘bool check(int)’
  116 | bool check(int v){
      |      ^~~~~
answer.code:16:6: note: ‘bool check(int)’ previously defined here
   16 | bool check(int v){
      |      ^~~~~
answer.code:152:5: error: redefinition of ‘int main()’
  152 | int main(){
      |     ^~~~
answer.code:77:5: note: ‘int main()’ previously defined here
   77 | int main(){
      |     ^~~~