#include "fish.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
using piii = pair<int,pair<int,int>>;
#ifdef DEBUG
#define dbg(x) cerr << "(" #x ") = " << x << '\n'
#define dbgln() cerr << '\n'
#else
#define dbg(x) void(0)
#define dbgln(x) void(0)
#endif
int max_weights(signed N, signed M, vector<signed> X, vector<signed> Y, vector<signed> W) {
vector<vector<int>> grid(N, vector<int>(N+2));
vector<vector<int>> cumulsum(N, vector<int>(N+2));
for (int i = 0; i < M; i++) grid[X[i]][Y[i]] = W[i];
for (int x = 0; x < N; x++) {
for (int y = 0; y <= N; y++) {
cumulsum[x][y+1] = cumulsum[x][y]+grid[x][y];
}
}
vector<vector<int>> best_asc(N, vector<int>(N+2)), best_desc(N, vector<int>(N+2));
for (int y = 0; y <= N+1; y++) {
best_asc[0][y] = cumulsum[0][y+1];
}
for (int x = 1; x < N; x++) {
vector<int> best_for_desc(N+3);
for (int y = N+1; y >= 0; y--) {
best_for_desc[y] = max(best_for_desc[y+1], best_desc[x-1][y]+cumulsum[x][y]);
}
int best_for_asc = 0;
for (int y = 0; y <= N+1; y++) {
best_for_asc = max(best_for_asc, best_asc[x-1][y]+cumulsum[x].back()-cumulsum[x][y+1]);
best_asc[x][y] = cumulsum[x][y+1];
if (y <= N) best_asc[x][y] = max(best_asc[x][y], cumulsum[x][y+1]+best_desc[x-1][y+1]);
best_asc[x][y] = max(best_asc[x][y], best_for_asc-(cumulsum[x].back()-cumulsum[x][y+1]));
if (x >= 2) {
best_desc[x][y] = max(best_desc[x][y], best_desc[x-2][N]);
}
if (x >= 3) {
best_desc[x][y] = max(best_desc[x][y], best_desc[x-3][N]);
}
best_desc[x][y] = max(best_desc[x][y], best_for_desc[y]);
}
}
for (int x = 0; x < N; x++) {
for (int y = 0; y <= N; y++) {
dbg(x);
dbg(y);
dbg(best_asc[x][y]);
dbg(best_desc[x][y]);
dbgln(), dbgln();
}
}
return max(best_desc[N-1][0], best_asc[N-2][N]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1064 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Runtime error |
656 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
980 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '310323004046' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
980 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '310323004046' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
980 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '310323004046' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1064 ms |
2097152 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |