#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define nL '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
int ipow(int a, int n) {
if (n == 0) return 1;
int x = ipow(a, n/2);
if (n % 2 == 0) return x*x;
return x*x*a;
}
template <typename T>
ostream& operator<<(ostream& stream, const vector<T>& v) {
for (auto elem : v)
stream << elem << " ";
return stream;
}
template <typename T>
istream& operator>>(istream& stream, vector<T>& v){
for(auto &elem : v)
stream >> elem;
return stream;
}
long long max_weights(int N, int M, vi X, vi Y,
vi W) {
ll maxY = 0;
for (int i = 0; i < M; i++) maxY = max(maxY, (ll)Y[i]);
maxY++;
vvl mat(N, vl(maxY+1));
for (int i = 0; i < M; i++) mat[X[i]][Y[i]] = W[i];
vector<vvl> dp(N, vvl(maxY+1, vl(maxY+1)));
int _tmp1 = 0;
for (int j = 0; j <= maxY; j++) {
if (j > 0) _tmp1 += mat[0][j-1];
int _tmp2 = 0;
for (int k = 0; k <= maxY; k++) {
if (k <= j) {
if (k > 0) _tmp2 -= mat[0][k-1];
} else {
if (k > 0) _tmp2 += mat[1][k-1];
}
dp[1][j][k] = _tmp1+_tmp2;
// cout << j << " " << k << " " << _tmp1+_tmp2 << nL;
}
}
for (int i = 2; i < N; i++) {
int tmp1 = 0;
for (int j = 0; j <= maxY; j++) {
if (j > 0) tmp1 += mat[i-1][j-1];
int tmp2 = 0;
for (int k = 0; k <= maxY; k++) {
if (k <= j) {
if (k > 0) tmp2 -= mat[i-1][k-1];
} else {
if (k > 0) tmp2 += mat[i][k-1];
}
int tmp3 = 0;
for (int l = 0; l <= maxY;l++) {
if (l > k && l <= j) {
if (l > 0) tmp3 -= mat[i-1][l-1];
}
dp[i][j][k] = max(dp[i][j][k], dp[i-1][k][l]+tmp1+tmp2+tmp3);
}
}
}
}
long long res = 0;
for (int i = 0; i <= maxY; i++) {
for (int j = 0; j <= maxY; j++)
res = max(res, dp[N-1][i][j]);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
844 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Runtime error |
846 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
20736 KB |
Output is correct |
2 |
Correct |
26 ms |
20572 KB |
Output is correct |
3 |
Correct |
29 ms |
20728 KB |
Output is correct |
4 |
Correct |
34 ms |
22096 KB |
Output is correct |
5 |
Correct |
47 ms |
25024 KB |
Output is correct |
6 |
Correct |
36 ms |
23888 KB |
Output is correct |
7 |
Correct |
39 ms |
24672 KB |
Output is correct |
8 |
Correct |
40 ms |
24656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '179515847393' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '179515847393' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
348 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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '179515847393' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
20736 KB |
Output is correct |
2 |
Correct |
26 ms |
20572 KB |
Output is correct |
3 |
Correct |
29 ms |
20728 KB |
Output is correct |
4 |
Correct |
34 ms |
22096 KB |
Output is correct |
5 |
Correct |
47 ms |
25024 KB |
Output is correct |
6 |
Correct |
36 ms |
23888 KB |
Output is correct |
7 |
Correct |
39 ms |
24672 KB |
Output is correct |
8 |
Correct |
40 ms |
24656 KB |
Output is correct |
9 |
Runtime error |
810 ms |
2097152 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
844 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |