이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll max_weights(int N, int M, vector <int> x, vector <int> y, vector <int> w) {
for (auto &it : x)
it++;
vector <ll> sum(N + 2);
vector <map <int, ll>> diff(N + 2);
for (int i = 0; i < M; i++) {
sum[x[i]] += w[i];
diff[x[i] + 1][y[i]] += w[i];
diff[x[i]][y[i]] -= w[i];
}
vector <ll> dp(5, -INF);
dp[0] = dp[1] = 0;
for (int i = 1; i <= N + 1; i++) {
auto update = [&](ll &ref, ll val) {
if (val > ref)
ref = val;
};
ll curr = 0;
vector <ll> trans(5);
trans[2] = sum[i - 1];
trans[3] = sum[i];
for (auto it : diff[i]) {
curr += it.second;
update(trans[1], curr);
update(trans[4], -curr);
}
vector <ll> nxt(5, -INF);
for (int j = 0; j < 5; j++) {
update(nxt[j], dp[(j + 4) % 5]);
if (j == 1 || j == 4)
update(nxt[j], dp[j]);
nxt[j] += trans[j];
}
dp = nxt;
}
return max({dp[0], dp[3], dp[4], 0ll});
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |