QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687940 | #9427. Collect the Coins | WilliamHu | WA | 11ms | 3848kb | C++17 | 2.5kb | 2024-10-29 22:01:04 | 2024-10-29 22:01:04 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read()
{
int x = 0, f = 1;
char c = getchar();
while(c != EOF and !isdigit(c))
{
if(c == '-')f = -1;
c = getchar();
}
while(isdigit(c))
{
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
struct node{
int t, c;
}a[1000010];
bool cmp(node x, node y)
{
if(x.t == y.t)return x.c < y.c;
return x.t < y.t;
}
int n;
bool checks()
{
for(int i = 1;i + 2 <= n;i ++)if(a[i].t == a[i+1].t and a[i+1].t == a[i+2].t)return true;
return false;
}
bool check(int mid)
{
if(n <= 2)return true;
int p = 1, q = -1, now = 1;
if(a[1].t == a[2].t)
{
now = p = 2;
q = 1;
}
for(int i = 2;i <= n;i ++)
{
if(a[i].t == a[i - 1].t)continue;
//cout<<p<<' '<<q<<' '<<now<<endl;
if(i + 1 <= n)
{
if(a[i].t == a[i + 1].t)
{
if(abs(a[i].c - a[now].c) > (a[i].t - a[now].t) * mid)
{
if(q != -1)
{
if((abs(a[i].c - a[p].c) > (a[i].t - a[p].t) * mid or abs(a[i+1].c - a[q].c) > (a[i+1].t - a[q].t) * mid))
{
//cout<<"cant\n";
if((abs(a[i+1].c - a[p].c) > (a[i+1].t - a[p].t) * mid or abs(a[i].c - a[q].c) > (a[i].t - a[q].t) * mid))
{
return false;
}
p = i + 1;
q = i;
now = i + 1;
continue;
}
}
else{
if(abs(a[i].c - a[p].c) > (a[i].t - a[p].t) * mid or (abs(a[i+1].c - a[p].c) > (a[i+1].t - a[p].t) * mid))
{
return false;
}
p = i + 1;
q = i;
now = i + 1;
continue;
}
}
//cout<<i<<"?"<<endl;
p = i + 1;
q = i;
now = i + 1;
continue;
}
}
if(abs(a[i].c - a[now].c) <= (a[i].t - a[now].t) * mid)
{
now = i;
continue;
}
if(q == -1 or abs(a[i].c - a[p].c) <= (a[i].t - a[p].t) * mid or abs(a[i].c - a[q].c) <= (a[i].t - a[q].t) * mid)
{
//cout<<"???\n";
q = now;
now = i;
p = i;
continue;
}
return false;
}
return true;
}
signed main()
{
int T = read();
while(T --)
{
n = read();
for(int i = 1;i <= n;i ++)
{
a[i].t = read();
a[i].c = read();
}
sort(a + 1, a + n + 1, cmp);
if(checks())
{
cout<<-1<<'\n';
continue;
}
int l = 0, r = 1e9, ans = -1;
//check(2);
while(l <= r)
{
int mid = l + r >> 1ll;
//cout<<mid<<endl;
if(check(mid))
{
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
cout<<ans<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 11ms
memory: 3848kb
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 3 0 3 1 3 6 0 3 2 2 0 2 7 0 1 1 1 3 0 0 0 1 4 2 0 2 1 3 0 3 2 3 2 5 2 1 1 0 1 1 1 0 1 0 1 0 1 0 2 1 0 2 3 4 2 1 1 1 0 1 3 0 1 4 4 2 0 0 1 2 6 4 2 1 0 0 1 0 2 1 2 0 1 1 2 0 0 1 2 0 3 0 2 2 2 1 0 0 0 5 1 2 0 6 1 1 1 2 2 0 0 3 1 4 3 4 0 8 1 1 1 0 2 2 4 1 1 0 0 0 3 2 2 1 0 0 3 2 2 1 1 2 2 3 0 3 3 3 5 ...
result:
wrong answer 14th lines differ - expected: '5', found: '7'