이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long max_weights(int32_t n, int32_t m, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> w) {
if (n > 2) {
vector<int> pref(n + 1, 0), suff(n + 1, 0), s0(n + 1, 0);
for (int i = 0; i < m; i++) {
if (x[i] == 0) {
pref[y[i]] += w[i];
s0[y[i]] += w[i];
}
else if (x[i] == 1) suff[y[i]] += w[i];
}
for (int i = 1; i < n; i++) pref[i] += pref[i-1];
for (int i = n - 2; i >= 0; i--) {
suff[i] += suff[i+1];
// s0[i] += s0[i + 1];
}
int ans = suff[0];
for (int i = 0; i < n; i++) {
ans = max(ans, pref[i] + suff[i + 1]);
// if (i < n - 1) ans = max(ans, suff[0] + s0[i + 1]);
}
return ans;
}
vector<vector<int>> a(2, vector<int> (n, 0));
for (int i = 0; i < m; i++) a[x[i]][y[i]] = w[i];
int ans = 0;
for (int i = 0; i < 2; i++) {
int tmp = 0;
for (int j = 1; j < n; j++) tmp = max(tmp, a[i][j]);
ans += tmp;
}
vector<int> pref(n + 1, 0), suff(n + 1, 0), s0(n + 1, 0), p0(n + 1, 0), p2(n + 1, 0);
for (int i = 0; i < m; i++) {
if (x[i] == 0) {
pref[y[i]] += w[i];
p0[y[i]] += w[i];
}
else if (x[i] == 1) {
suff[y[i]] += w[i];
s0[y[i]] += w[i];
p2[y[i]] += w[i];
}
}
for (int i = 1; i < n; i++) {
pref[i] += pref[i-1];
p2[i] += p2[i - 1];
}
for (int i = n - 2; i >= 0; i--) {
suff[i] += suff[i+1];
// s0[i] += s0[i + 1];
}
// int ans = suff[0];
for (int i = 0; i < n; i++) {
ans = max(ans, pref[i]);
ans = max(ans, p2[i]);
// if (i < n - 1) ans = max(ans, suff[0] + s0[i + 1]);
}
return ans;
}
#ifndef EVAL
int32_t main() {
int32_t N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int32_t> X(M), Y(M), W(M);
for (int32_t i = 0; i < M; ++i) {
assert(3 == scanf("%d %d %d", &X[i], &Y[i], &W[i]));
}
long long result = max_weights(N, M, X, Y, W);
printf("%lld\n", result);
return 0;
}
#endif
# | 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... |