QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751718 | #4906. 球球 | NineSuns | 5 | 18ms | 28284kb | C++14 | 1.8kb | 2024-11-15 20:16:56 | 2024-11-15 20:16:56 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5005, inf = 0x3f3f3f3f3f3f3f3f;
int n, g[N], t[N], x[N];
bool f[N][N];
void solve () {
cin >> n;
for (int i = 1;i <= n;i++) cin >> t[i] >> x[i];
memset(g, 0x3f, sizeof g);
g[0] = 0;
for (int i = 0;i <= n;i++) {
if (i) g[i] = min(g[i], max(t[i-1], g[i-1])+llabs(x[i]-x[i-1]));
if (i && x[i] == x[i-1]) g[i] = min(g[i], g[i-1]);
if (g[i] > t[i]) g[i] = inf;
if (i && f[i-1][i] && i < n) {
g[i+1] = min(g[i+1], max(t[i], t[i-1]+abs(x[i+1]-x[i-1])));
for (int j = i+1;j <= n;j++) f[i+1][j] |= t[i+1]-max(t[i], t[i-1]+llabs(x[i-1]-x[j])) >= llabs(x[j]-x[i+1]); //, cout << i << " " << j << " " << "DCHK:" << t[i+1]-t[i-1] << " " << abs(x[i]-x[j]) << " " << abs(x[j]-x[i+1]) << " " << f[i+1][j] << endl;
}
if (g[i] <= t[i] && i < n) {
for (int j = i+1;j <= n;j++) f[i+1][j] |= t[i+1]-max(t[i], g[i]+llabs(x[i]-x[j])) >= llabs(x[j]-x[i+1]);
// for (int j = i+1;j <= n;j++) f[i+1][j] |= (t[i+1]-g[i]) >= abs(x[i]-x[j])+abs(x[j]-x[i+1]); //, cout << i << " " << j << " " << "CHK:" << t[i+1]-g[i] << " " << abs(x[i]-x[j]) << " " << abs(x[j]-x[i+1]) << " " << f[i+1][j] << endl;
}
for (int j = 0;j <= n;j++) f[i+1][j] |= f[i][j]&(t[i+1]-t[i] >= llabs(x[i+1]-x[i]));
// for (int j = 0;j <= n;j++) cout << f[i][j] << " "; cout << endl;
// cout << g[i] << endl;
} // cout << endl;
int fl = g[n] <= t[n] || f[n-1][n];
for (int j = 0;j <= n;j++) fl |= f[n][j];
puts(fl ? "YES" : "NO");
}
signed main () {
int T = 1;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 3708kb
input:
5 2 1 3 2 9 6 10 5 13 -1
output:
NO
result:
ok single line: 'NO'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3712kb
input:
5 1 1 3 2 4 -1 6 4 10 -1
output:
NO
result:
ok single line: 'NO'
Test #3:
score: 5
Accepted
time: 0ms
memory: 3760kb
input:
4 16 13 18 4 20 3 21 5
output:
NO
result:
ok single line: 'NO'
Test #4:
score: 5
Accepted
time: 0ms
memory: 3688kb
input:
5 2 1 3 2 8 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #5:
score: 5
Accepted
time: 0ms
memory: 3716kb
input:
5 2 1 3 2 9 6 10 5 13 0
output:
YES
result:
ok single line: 'YES'
Test #6:
score: 5
Accepted
time: 0ms
memory: 3708kb
input:
5 1 1 3 2 4 0 6 4 10 -1
output:
YES
result:
ok single line: 'YES'
Test #7:
score: 5
Accepted
time: 0ms
memory: 3696kb
input:
3 1 0 5 5 6 2
output:
YES
result:
ok single line: 'YES'
Test #8:
score: 5
Accepted
time: 0ms
memory: 3772kb
input:
5 2 1 6 0 7 -1 8 2 9 -2
output:
YES
result:
ok single line: 'YES'
Test #9:
score: 5
Accepted
time: 0ms
memory: 3784kb
input:
5 30 10 40 -10 51 9 52 8 53 20
output:
YES
result:
ok single line: 'YES'
Test #10:
score: 5
Accepted
time: 0ms
memory: 3700kb
input:
3 2 2 5 5 6 1
output:
YES
result:
ok single line: 'YES'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #11:
score: 0
Wrong Answer
time: 1ms
memory: 4228kb
input:
100 51823 -51823 80072 -23574 152202 48556 263343 -14629 356859 -38607 441850 -193136 442857 -192129 471412 -108145 504392 -187704 582081 -265393 680615 -220684 775219 -261463 781624 -267868 801370 -287614 899570 -166859 982377 -272221 1048767 -338611 1094930 -189414 1170308 -460152 1222829 -512673 ...
output:
NO
result:
wrong answer 1st lines differ - expected: 'YES', found: 'NO'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #91:
score: 0
Wrong Answer
time: 18ms
memory: 28284kb
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%