#include <cstdio>
#ifdef DEBUG
#define D(X) X
#else
#define D(X)
#endif
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pi 3.14159265359
#define pub push_back
#define pob pop_back
#define pari pair<int,int>
#define parli pair<long, long>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
vector<vector<ll>> cnt(n + 1, vector<ll>(n+1, 0));
//vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(n + 1, vector<ll>(n + 1 , 0)));
for(int i=0; i<m; i++) {
cnt[x[i]][y[i]+1] += w[i];
}
for(int i=0; i<n; i++) {
for(int j=1; j<=n; j++) {
cnt[i][j] += cnt[i][j-1];
}
}
//vector<vector<ll>> suf(n + 1, vector<ll>(n + 1, 0)), pref(n + 1, vector<ll>(n + 1, 0)), suf2(n + 1, vector<ll>(n + 1, 0));
//vector<vector<ll>> pref2(n + 1, vector<ll>(n + 1, 0));
vector<vector<ll>> pref(n+1, vector<ll>(n+1, 0));
vector<vector<ll>> suf(n+1, vector<ll>(n+1, 0));
vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(2, 0)));
ll res = 0;
for(int i=1; i<n; i++) {
if(i==1) {
pref[i-1][0] = 0;
} else
{
pref[i-1][0] = dp[i-2][0][0];
}
for(int j=1; j<=n; j++) {
pref[i-1][j] = max(pref[i-1][j-1], dp[i-1][j][1] - cnt[i-1][j]);
}
suf[i-1][n] = cnt[i][n] + max(dp[i-1][n][0], dp[i-1][n][1]);
for(int j=n-1; j>=1; j--) {
suf[i-1][j] = max(suf[i-1][j+1], max(dp[i-1][j][0], dp[i-1][j][1]) + cnt[i][j]);
}
dp[i][0][0] = dp[i][0][1] = max(suf[i-1][1], dp[i-1][0][0]);
for(int j=1; j<=n; j++) {
dp[i][j][0] = suf[i-1][j] - cnt[i][j];
dp[i][j][1] = cnt[i-1][j] + pref[i-1][j];
//res = max(res, max(dp[i][j][0], dp[i][j][1]));
}
}
for(int i=0; i<n; i++)
for(int j=0; j<=n; j++) {
for(int bin=0; bin<2; bin++)
res = max(res, dp[i][j][bin]);
}
return res;
}
/*
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
D(freopen("input.txt","r",stdin);)
//D(freopen("ouput.txt","w",stdout);)
int t = 1;
//cin >> t;
loop:
while(t--)
{
int n, m;
cin >> n >> m;
vector<int> x(m), y(m), w(m);
for(int i=0; i<m; i++) {
cin >> x[i];
}
for(int i=0; i<m; i++) {
cin >> y[i];
}
for(int i=0; i<m; i++) {
cin >> w[i];
}
ll res = max_weights(n, m, x, y, w);
cout << res;
}
return 0;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
855 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 |
Runtime error |
779 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
737 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
2 ms |
2140 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
2 ms |
2140 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
2 ms |
2140 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '214837477243' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
737 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
855 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |