QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687828 | #9427. Collect the Coins | WilliamHu | WA | 10ms | 5812kb | C++17 | 2.0kb | 2024-10-29 21:28:55 | 2024-10-29 21:28:55 |
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<<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 and abs(a[i].c - a[q].c) > (a[i].t - a[q].t) * mid))
{
//cout<<"cant\n";
return false;
}
}
}
//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)
{
now = i;
p = i;
q = i - 1;
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(1);
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
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: 10ms
memory: 5812kb
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 2 2 1 0 1 0 0 1 1 1 2 0 0 0 1 4 1 0 2 1 3 0 3 2 2 2 5 2 0 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 3 4 2 0 0 1 1 2 3 2 1 0 0 1 0 2 1 2 0 1 1 2 0 0 1 2 0 2 0 2 2 2 1 0 0 0 5 1 2 0 6 1 1 1 2 2 0 0 3 1 1 3 4 0 8 1 1 1 0 2 1 4 1 1 0 0 0 3 1 2 1 0 0 3 1 2 1 1 2 1 3 0 3 3 1 4 ...
result:
wrong answer 9th lines differ - expected: '3', found: '2'