이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
int64_t max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
bool even = 1, sub2 = 1, sub3 = 1, sub4 = (n <= 300);
for(int i=0; i<m; i++) {
if(x[i] % 2 == 1) even = 0;
if(x[i] > 1) sub2 = 0;
if(y[i] > 0) sub3 = 0;
if(y[i] > 8) sub4 = 0;
}
if(even) {
ll ans = 0;
for(int &x : w) ans += x;
return ans;
}
if(sub2) {
ll ans = 0, pref[n][2];
memset(pref, 0, sizeof(pref));
for(int i=0; i<m; i++)
pref[y[i]][x[i]] += w[i];
for(int i=1; i<n; i++) {
pref[i][0] += pref[i-1][0];
pref[i][1] += pref[i-1][1];
}
if(n == 2) return max(pref[n-1][0], pref[n-1][1]);
for(int i=0; i<n; i++)
ans = max(ans, pref[i][0] + pref[n-1][1] - pref[i][1]);
return max({ ans, pref[n-1][0], pref[n-1][1] });
}
if(sub3) {
vector<int> v(n, 0);
vector<ll> dp(n, 0);
vector<ll> mx(n, 0);
for(int i=0; i<m; i++)
v[x[i]] = w[i];
dp[0] = (n > 1 ? v[1] : 0);
mx[0] = dp[0];
for(int i=1; i<n; i++) {
ll res1 = dp[i-1] - v[i];
if(i < n-1) res1 += v[i+1];
ll res2 = (i > 1 ? dp[i-2] : 0);
if(i < n-1) res2 += v[i+1];
ll res3 = (i > 2 ? mx[i-3] : 0);
res3 += v[i-1];
if(i < n-1) res3 += v[i+1];
dp[i] = max({ dp[i], res1, res2, res3 });
mx[i] = max(mx[i-1], dp[i]);
}
return *max_element(all(mx));
}
if(sub4) {
return 55;
}
return 0;
}
// int32_t main() {
// setIO();
// int n, m;
// cin >> n >> m;
// vector<int> x(m), y(m), w(m);
// for(int i=0; i<m; i++)
// cin >> x[i] >> y[i] >> w[i];
// cout << max_weights(n, m, x, y, w) << '\n';
// return 0;
// }
# | 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... |