QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624306 | #9427. Collect the Coins | ucup-team4153# | WA | 13ms | 5964kb | C++20 | 2.5kb | 2024-10-09 15:30:12 | 2024-10-09 15:30:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
using pii=pair<int,int>;
const int N=1e6+5;
const int INF=1e9+117;
int n,t[N],c[N];
vector<pair<int,pii>>arr;
bool itc(int l1,int r1,int l2,int r2){return max(l1,l2)<=min(r1,r2);}
bool DtL(int d,int l,int r,int len)
{
// cout<<d<<','<<l<<','<<r<<','<<len<<','<<itc(d-len,d+len,l,r)<<"***\n";
return itc(d-len,d+len,l,r);
}
bool check(int v){
//int rx=1,ry=INF,lx=1,ly=INF;
int lst=0;\
int p=arr[0].second.first,l=1,r=INF;//1:r_fx
//cout<<v<<"---------------------\n";
for(auto&k:arr)
{
int t=k.first,pl=k.second.first,pr=k.second.second;
int len=v*(t-lst);lst=t;
//cout<<t<<"*"<<len<<"|"<<pl<<"&"<<pr<<'\n';
if(pr!=-1)
{
if(DtL(pl,p,p,len)&&DtL(pr,l,r,len))l=r=pl,p=pr;
else if(DtL(pr,p,p,len)&&DtL(pl,l,r,len))l=r=pl,p=pr;
else return 0;
}
else
{
bool dok=DtL(pl,p,p,len),lok=DtL(pl,l,r,len);
//cout<<dok<<"%%"<<lok<<'\n';
int p2=p,l2,r2;
if(dok&&lok)
{
r2=max(p,r)+len,l2=min(p,l)-len;
}
else if(dok)
{
r2=r+len,l2=l-len;
}
else if(lok)
{
r2=p+len,l2=p-len;
}
else return 0;
l=l2,r=r2,p=p2;
}
//cout<<p<<','<<l<<','<<r<<'\n';
// cout<<"^^^^^^^\n";
}
return 1;
}
void solve()
{
cin>>n;arr.clear();
for(int i=1;i<=n;i++){
cin>>t[i]>>c[i];
}
pii p={-1,-1};int lst=t[1];
for(int i=1;i<=n;i++)
{
if(lst==t[i])
{
if(p.second!=-1){cout<<"-1\n";return;}
if(p.first==-1)p.first=c[i];else p.second=c[i];
}
else
{
arr.push_back({lst,p});
lst=t[i];p={c[i],-1};
}
if(i==n)arr.push_back({lst,p});
}
for(auto&k:arr)
{
auto&[a,b]=k.second;
if(b!=-1&&a>b)swap(a,b);
//cout<<k.first<<','<<a<<','<<b<<'\n';
}
// cout<<"**\n";
int l=-1,r=INF,mid;
while(r-l>1){
mid=(l+r)/2;
if(check(mid)){
r=mid;
}else{
l=mid;
}
}
if(r>INF-10)r=-1;
cout<<r<<'\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t=1;cin>>t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5776kb
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
2 0 -1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 13ms
memory: 5964kb
input:
1135 2 6 5 8 8 8 2 9 2 10 4 4 5 3 6 2 6 8 8 2 8 7 1 9 1 6 4 6 6 1 6 2 9 10 10 1 10 7 5 1 6 2 5 6 7 8 6 10 3 8 1 10 5 4 5 7 6 1 6 6 8 4 9 1 9 4 8 1 1 1 3 2 9 3 3 5 9 6 10 9 7 10 7 3 5 8 6 6 10 6 7 2 9 4 7 5 10 6 3 6 7 8 9 10 1 6 1 4 2 8 5 9 7 10 9 1 10 5 9 2 7 4 5 5 9 6 10 7 4 9 4 9 9 10 3 10 7 1 3 1...
output:
0 4 0 3 1 3 6 1 2 2 2 0 1 5 0 1 5 1 4 2 0 1 1 4 2 0 2 2 3 0 6 2 3 2 8 4 1 1 0 1 1 2 0 2 0 1 0 1 0 2 1 0 3 3 4 4 2 2 1 0 1 3 0 1 4 5 3 0 0 2 2 6 3 3 1 0 0 1 0 2 1 2 0 1 1 2 0 0 1 1 0 3 0 2 2 3 1 0 0 0 5 1 2 0 6 1 1 1 2 2 2 5 4 1 4 4 4 0 8 1 1 2 0 4 2 4 1 3 0 0 0 3 2 2 1 0 0 4 1 2 1 1 2 5 3 0 3 4 3 5 ...
result:
wrong answer 2nd lines differ - expected: '3', found: '4'