QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#544062 | #8257. Marathon Race 2 | Bucketsmith | 0 | 36ms | 789996kb | C++20 | 2.2kb | 2024-09-02 02:13:19 | 2024-09-02 02:13:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 5e5 + 10, M = 5010;
int n, L, pb[N];
vector<int> balls;
int cnt[M][M];
i64 dp[M][M][4];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> L;
for(int i = 1, x; i <= n; i ++) {
cin >> x;
pb[x] ++;
balls.push_back(x);
}
sort(balls.begin(), balls.end());
int m = unique(balls.begin(), balls.end()) - balls.begin();
while(balls.size() > m) balls.pop_back();
if(m > M) {
int q;
cin >> q;
for(int i = 0; i < q; i ++)
cout << "No\n";
return 0;
}
memset(dp, 0x3f, sizeof dp);
dp[0][m - 1][0] = dp[0][m - 1][3] = 0;
for(int i = 0; i < m; i ++)
for(int j = i; j < m; j ++)
cnt[i][j] = (j ? cnt[i][j - 1] : 0) + pb[balls[j]];
for(int len = m - 2; len >= 0; len --) {
for(int l = 0; l + len < m; l ++) {
int r = l + len;
for(int i : {0, 1})
for(int j : {0, 2}) {
int p = j ? balls[r] : balls[l];
if(l > 0) dp[l][r][i | j] = min(dp[l][r][i | j], dp[l - 1][r][i] + (n - cnt[l][r] + 1) * (i64)abs(p - balls[l - 1]));
if(r + 1 < m) dp[l][r][i | j] = min(dp[l][r][i | j], dp[l][r + 1][i | 2] + (n - cnt[l][r] + 1) * (i64)abs(p - balls[r + 1]));
cout << "dp[" << l << "," << r << "," << (i | j) << " = " << dp[l][r][i | j] << "\n";
}
}
}
int q;
cin >> q;
for(int i = 1, s, g, t; i <= q; i ++) {
cin >> s >> g >> t;
int ans = INT_MAX;
auto p = lower_bound(balls.begin(), balls.end(), g) - balls.begin();
if(p < m) ans = min((i64)ans, n + abs(g - balls[p]) * (n + 1ll) + min(dp[p][p][0] + abs(s - balls.front()), dp[p][p][1] + abs(s - balls.back())));
p --;
if(p >= 0) ans = min((i64)ans, n + abs(g - balls[p]) * (n + 1ll) + min(dp[p][p][0] + abs(s - balls.front()), dp[p][p][1] + abs(s - balls.back())));
cout << (ans <= t ? "Yes\n" : "No\n");
}
}
/*
3 100
30 80 30
3
0 0 403
0 0 300
0 0 262
6 100
0 50 100 0 50 100
4
20 70 600
70 20 600
10 40 600
40 10 600
*/
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 35ms
memory: 788068kb
input:
1 500000 166666 10 0 0 500000 0 0 499999 0 0 499998 0 0 499997 0 0 499996 0 0 5 0 0 4 0 0 3 0 0 2 0 0 1
output:
Yes Yes No No No No No No No No
result:
ok 10 token(s): yes count is 2, no count is 8
Test #2:
score: 7
Accepted
time: 23ms
memory: 789996kb
input:
1 500000 0 10 0 0 500000 0 0 499999 0 0 499998 0 0 499997 0 0 499996 0 0 5 0 0 4 0 0 3 0 0 2 0 0 1
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
result:
ok 10 token(s): yes count is 10, no count is 0
Test #3:
score: 0
Wrong Answer
time: 36ms
memory: 789992kb
input:
2 1 0 1 10 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0 10
output:
dp[0,0,0 = 4557430888798830399 dp[0,0,2 = 4557430888798830399 dp[0,0,1 = 2 dp[0,0,3 = 2 dp[1,1,0 = 2 dp[1,1,2 = 2 dp[1,1,1 = 4557430888798830399 dp[1,1,3 = 4557430888798830399 No No No No Yes Yes Yes Yes Yes Yes
result:
wrong output format YES or NO expected, but DP[0,0,0 found [1st token]
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%