#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define NL '\n'
#define EL cout << NL
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define FORS(i,s,n) for(int i = (s); i < (n); i++)
#define PRINTV(v) for(auto a:v) {cout << a << " ";} EL;
#define PRINTVV(v) for(auto a:v) {PRINTV(a);}
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define STRP(p) "{" << (p).f << "," << (p).s << "}"
#define PRINTVP(v) for(auto a:v) {cout << STRP(a) << " ";} EL;
#define PRINTVVP(v) for(auto a:v) {PRINTVP(a);}
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vpl;
typedef vector<vpl> vvpl;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
vvl a(N,vl(N));
FOR(i,M) {
a[X[i]][Y[i]] = W[i];
}
vvl dp_up(N,vl(N,-1e18));
vvl dp_down(N,vl(N,-1e18));
FOR(i,N-1) {
dp_up[i][0] = a[i][0];
}
FORS(i,1,N) {
dp_down[i][N-1] = a[i][N-1];
}
FOR(i,N) {
FOR(j,N) {
if (j >= 1) {
dp_up[i][j] = max(dp_up[i][j],dp_up[i][j-1] + a[i][j]);
if (i >= 1) {
dp_up[i][j] = max(dp_up[i][j],dp_up[i-1][j-1] + a[i][j]);
}
}
FORS(k,i-6,i) {
if (k < 0) continue;
dp_up[i][j] = max(dp_up[i][j],dp_down[k][j] + a[i][j]);
}
if (dp_up[i][j] < 0) dp_up[i][j] = -1e18;
}
FOR(_j,N) {
ll j = N-_j-1;
if (j < N-1) {
dp_down[i][j] = max(dp_down[i][j],dp_down[i][j+1] + a[i][j]);
if (i >= 1) {
dp_down[i][j] = max(dp_down[i][j],dp_down[i-1][j+1] + a[i][j]);
}
}
FORS(k,i-6,i-1) {
if (k < 0) continue;
dp_down[i][j] = max(dp_down[i][j],dp_up[k][j] + a[i][j]);
}
if (dp_down[i][j] < 0) dp_down[i][j] = -1e18;
}
}
// PRINTVV(a); EL;
// FOR(_j,N) {
// ll j = N-_j-1;
// FOR(i,N) {
// cout << a[i][j] << " ";
// }
// EL;
// } EL;
// FOR(_j,N) {
// ll j = N-_j-1;
// FOR(i,N) {
// cout << dp_up[i][j] << " ";
// }
// EL;
// } EL;
// FOR(_j,N) {
// ll j = N-_j-1;
// FOR(i,N) {
// cout << dp_down[i][j] << " ";
// }
// EL;
// } EL;
ll ans = 0;
FOR(i,N-1) {
FOR(j,N) {
ans = max(ans,dp_up[i][j]);
}
}
FOR(i,N) {
FOR(j,N) {
ans = max(ans,dp_down[i][j]);
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1153 ms |
2042564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
991 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
725 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
352 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
860 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
725 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1153 ms |
2042564 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |