QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#637082 | #9427. Collect the Coins | Idtwtei | WA | 0ms | 6608kb | C++14 | 1.7kb | 2024-10-13 08:33:53 | 2024-10-13 08:33:53 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define mp make_pair
using namespace std;
typedef long long ll;
int n;
int t[1000005],x[1000005];
inline bool judge(int k){
int t1=1e9,t2=1e9;
int p1=x[n],p2=x[n];
bool vis[1000005];
memset(vis,0,sizeof(vis));
for(int i=n;i>=1;i--){
if(vis[i]) continue;
bool ava1=0,ava2=0;
if((t1-t[i])*k>=abs(p1-x[i])){
ava1=1;
}
if((t2-t[i])*k>=abs(p2-x[i])){
ava2=1;
}
if(ava1&&ava2){
int nexp=-1;
int tnow=t[i],xnow=x[i];
for(int j=i;j>=1;j--){
if((tnow-t[j])*k>=abs(xnow-x[j])){
vis[j]=1;
tnow=t[j];
xnow=x[j];
}else{
nexp=j;
break;
}
}
if(nexp==-1){
return 1;
}
if((t1-t[nexp])*k>=abs(p1-x[nexp])){
p1=x[nexp];
t1=t[nexp];
vis[nexp]=1;
p2=xnow;
t2=tnow;
continue;
}else if((t2-t[nexp])*k>=abs(p2-x[nexp])){
p2=x[nexp];
t2=t[nexp];
vis[nexp]=1;
p1=xnow;
t1=tnow;
continue;
}else{
return 0;
}
}else if(ava1){
vis[i]=1;
p1=x[i];
t1=t[i];
}else if(ava2){
vis[i]=1;
p2=x[i];
t2=t[i];
}else{
return 0;
}
}
return 1;
}
signed main(){
// freopen("coin.in","r",stdin);
// freopen("coin.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
int cnt=0;
int l=0,r=0;
for(int i=1;i<=n;i++){
cin>>t[i]>>x[i];
if(i!=1){
if(t[i]==t[i-1]){
cnt++;
if(cnt==3){
cout<<"-1\n";
return 0;
}
}else{
r=max(r,1+abs(x[i]-x[i-1])/(t[i]-t[i-1]));
cnt=1;
}
}
}
while(l<r){
int mid=(l+r)>>1;
if(judge(mid)){
r=mid;
}else{
l=mid+1;
}
}
cout<<l<<'\n';
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 6608kb
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'