QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#88810 | #4906. 球球 | zhouhuanyi | 0 | 42ms | 3608kb | C++23 | 1.4kb | 2023-03-17 15:51:05 | 2023-03-17 15:51:08 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 5000
#define inf 1e18
using namespace std;
int read()
{
char c=0;
int sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
void Adder(long long &x,long long d)
{
x=(x<d)?x:d;
return;
}
struct reads
{
long long t,x;
};
reads st[N+1];
int n,pv[N+1];
long long dp[N+1][2];
int main()
{
n=read();
for (int i=1;i<=n;++i) st[i].t=read(),st[i].x=read();
for (int i=1;i<=n;++i)
{
if (abs(st[i-1].x-st[i].x)<=st[i].t-st[i-1].t) pv[i]=pv[i-1];
else pv[i]=i;
}
for (int i=0;i<=n;++i) dp[i][0]=dp[i][1]=inf;
dp[0][0]=0;
for (int i=1;i<=n;++i)
for (int j=1;j<=i;++j)
{
if (j==i)
{
if (max(dp[j-1][0]+abs(st[j-1].x-st[i].x),st[j-1].t)<=st[i].t) Adder(dp[i][0],max(dp[j-1][0]+abs(st[j-1].x-st[i].x),st[j-1].t));
if (max(dp[j-1][1]+abs(st[j-2].x-st[i].x),st[j-1].t)<=st[i].t) Adder(dp[i][0],max(dp[j-2][1]+abs(st[j-2].x-st[i].x),st[j-1].t));
}
else
{
if (max(dp[j-1][0]+abs(st[j-1].x-st[i].x),st[j-1].t)+abs(st[i].x-st[j].x)<=st[j].t&&j>=pv[i-1]) Adder(dp[i][1],st[i-1].t);
if (max(dp[j-1][1]+abs(st[j-2].x-st[i].x),st[j-1].t)+abs(st[i].x-st[j].x)<=st[j].t&&j>=pv[i-1]) Adder(dp[i][1],st[i-1].t);
}
}
puts((dp[n][0]!=inf||dp[n][1]!=inf)?"YES":"NO");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 2ms
memory: 3436kb
input:
5 2 1 3 2 9 6 10 5 13 -1
output:
NO
result:
ok single line: 'NO'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3204kb
input:
5 1 1 3 2 4 -1 6 4 10 -1
output:
NO
result:
ok single line: 'NO'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
4 16 13 18 4 20 3 21 5
output:
NO
result:
ok single line: 'NO'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
5 2 1 3 2 8 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
5 2 1 3 2 9 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #6:
score: -5
Wrong Answer
time: 1ms
memory: 3288kb
input:
5 1 1 3 2 4 0 6 4 10 -1
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #91:
score: 0
Wrong Answer
time: 42ms
memory: 3608kb
input:
5000 6 6 80 80 170 48 240 106 243 179 329 176 412 93 485 176 552 249 555 316 613 371 650 313 733 251 735 253 736 334 815 254 893 333 943 255 965 227 1022 284 1116 205 1174 320 1230 376 1318 378 1336 288 1430 212 1494 276 1562 344 1597 309 1638 350 1716 272 1793 349 1809 365 1908 306 1951 464 2037 42...
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%