# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
698168 |
2023-02-12T18:33:17 Z |
BidoTeima |
Go (COCI18_go) |
C++17 |
|
1000 ms |
235808 KB |
#include <iostream>
#include <vector>
using namespace std;
int dp[105][105][3005][2];
int a[105], b[105], t[105];
int n, k, m;
int cost(int i, int j, bool onWho, bool toWho) {
//to i - 1
if (!toWho) {
if (i == 0)return -1;
if (!onWho) {
return a[i] - a[i - 1];
}
return a[j] - a[i - 1];
}
// to j + 1
if (j == m - 1)return -1;
if (!onWho) {
return a[j + 1] - a[i];
}
return a[j + 1] - a[j];
}
int main()
{
cin >> n >> k >> m;
for (int i = 0; i < m; i++)
cin >> a[i] >> b[i] >> t[i];
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < 3005; k++) {
dp[i][j][k][0] = dp[i][j][k][1] = - 1e9;
}
}
}
int nearest_left = 0, nearest_right = 0;
for (int i = 0; i < m && a[i] <= k; i++) {
nearest_left = i;
}
for (int i = m - 1; i >= 0 && a[i] >= k; i--) {
nearest_right = i;
}
int dist = k - a[nearest_left];
dp[nearest_left][nearest_left][dist][1] =
dp[nearest_left][nearest_left][dist][0] = (dist < t[nearest_left] ? b[nearest_left] : 0);
dist = a[nearest_right] - k;
dp[nearest_right][nearest_right][dist][1] =
dp[nearest_right][nearest_right][dist][0] = (dist < t[nearest_right] ? b[nearest_right] : 0);
int ans = 0;
for(int aaa = 0; aaa < 10; aaa++)for (int i = 0; i < m; i++) {
for (int x = 0; x < m; x++) {
int j = i + x;
if (j >= m)break;
for (int curTime = 0; curTime < 3000; curTime++) {
for (int on = 0; on < 2; on++) {
ans = max(ans, dp[i][j][curTime][on]);
// 0 means on i, 1 means on j
// option 1: transition to [i - 1][j]
int v = cost(i, j, on, 0);
if (i > 0 && curTime + v <= 3000) {
int tot = curTime + v;
dp[i - 1][j][tot][0] =
dp[i][j][curTime][on] + (tot < t[i - 1] ? b[i - 1] : 0);
ans = max(ans, dp[i - 1][j][tot][0]);
}
// option 2: transition to [i][j + 1]
v = cost(i, j, on, 1);
if (j < m - 1 && curTime + v <= 3000) {
int tot = curTime + v;
dp[i][j + 1][tot][1] =
dp[i][j][curTime][on] + (tot < t[j + 1] ? b[j + 1] : 0);
ans = max(ans, dp[i][j + 1][tot][1]);
}
}
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
25 ms |
2644 KB |
Output is correct |
3 |
Correct |
51 ms |
5004 KB |
Output is correct |
4 |
Correct |
114 ms |
9852 KB |
Output is correct |
5 |
Incorrect |
635 ms |
59432 KB |
Output isn't correct |
6 |
Correct |
945 ms |
85404 KB |
Output is correct |
7 |
Execution timed out |
1099 ms |
115916 KB |
Time limit exceeded |
8 |
Execution timed out |
1090 ms |
151116 KB |
Time limit exceeded |
9 |
Execution timed out |
1107 ms |
191180 KB |
Time limit exceeded |
10 |
Execution timed out |
1092 ms |
235808 KB |
Time limit exceeded |