#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;
int n, m;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
n = N;
m = M;
vector<vll> grid(n, vll(n+1));
frange(i, m) {
grid[X[i]][Y[i]+1] = W[i];
}
vector<vll> dp1(n, vll(n+1)), dp2(n, vll(n+1));
forr(i, 1, n+1) {
dp2[0][i] = grid[0][i];
dp2[0][i] += dp2[0][i-1];
}
forr(i, 1, n) {
lli ma = 0;
frange(j, n+1) ma = max(ma, dp1[i-1][j]);
deque<lli> dq;
lli tot = 0;
frange(j, n+1) {
tot += grid[i][j];
lli v = dp2[i-1][j] - tot;
while(dq.size() && dq.back() <= v) dq.pop_back();
dq.pb(v);
dp2[i][j] = dq.front() + tot;
dp2[i][j] = max(dp2[i][j], ma + tot);
}
tot = 0;
dq = {};
for(int j=n; j>=0; j--) {
dp1[i][j] = dp2[i-1][j];
if(dq.size()) {
dp1[i][j] = max(dp1[i][j], dq.front() + tot);
}
lli v = dp1[i-1][j] - tot;
while(dq.size() && dq.back() <= v) dq.pop_back();
dq.pb(v);
tot += grid[i][j];
}
}
return *max_element(all(dp1[n-1]));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
923 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
920 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
864 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
2572 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
2608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
2572 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
2608 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
15 ms |
3540 KB |
Output is correct |
18 |
Correct |
10 ms |
3536 KB |
Output is correct |
19 |
Correct |
10 ms |
3652 KB |
Output is correct |
20 |
Correct |
10 ms |
3532 KB |
Output is correct |
21 |
Correct |
10 ms |
3420 KB |
Output is correct |
22 |
Correct |
18 ms |
4572 KB |
Output is correct |
23 |
Correct |
4 ms |
2652 KB |
Output is correct |
24 |
Correct |
8 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
4 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 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 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
2572 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
3 ms |
2608 KB |
Output is correct |
15 |
Correct |
2 ms |
2392 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
15 ms |
3540 KB |
Output is correct |
18 |
Correct |
10 ms |
3536 KB |
Output is correct |
19 |
Correct |
10 ms |
3652 KB |
Output is correct |
20 |
Correct |
10 ms |
3532 KB |
Output is correct |
21 |
Correct |
10 ms |
3420 KB |
Output is correct |
22 |
Correct |
18 ms |
4572 KB |
Output is correct |
23 |
Correct |
4 ms |
2652 KB |
Output is correct |
24 |
Correct |
8 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
2396 KB |
Output is correct |
26 |
Correct |
4 ms |
2652 KB |
Output is correct |
27 |
Correct |
201 ms |
212036 KB |
Output is correct |
28 |
Correct |
57 ms |
22356 KB |
Output is correct |
29 |
Correct |
253 ms |
224596 KB |
Output is correct |
30 |
Correct |
267 ms |
224612 KB |
Output is correct |
31 |
Correct |
267 ms |
224592 KB |
Output is correct |
32 |
Correct |
63 ms |
19536 KB |
Output is correct |
33 |
Correct |
265 ms |
224876 KB |
Output is correct |
34 |
Correct |
277 ms |
225000 KB |
Output is correct |
35 |
Correct |
214 ms |
216656 KB |
Output is correct |
36 |
Correct |
263 ms |
224848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
864 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
923 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |