이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
#include "fish.h"
ll max_weights(int N, int M, vector<int> X_g, vector<int> Y_g, vector<int> W_g) {
vi a(N);
for (int i = 0; i < M; i++) {
a[X_g[i]] += W_g[i];
}
/* cout<<"a: ";
for (ll x : a)
cout<<x<<" ";
cout<<endl;*/
vector<vi> dp(N + 1, vi(2, 0));
// dp[i][j]: max sum till i, exclusive; j = 0 if no pier, j = 1 if has
dp[0][1] = -1e18;
for (int i = 1; i <= N; i++) {
// a[i - 1] is empty
dp[i][0] = dp[i - 1][0];
dp[i][0] = max(dp[i][0], dp[i - 1][1] + a[i - 1]);
// a[i - 1] is filled
dp[i][1] = dp[i - 1][1]; // left also filled
if (i >= 2)
dp[i][1] = max(dp[i][1], max(dp[i - 2][0], dp[i - 2][1]) + a[i - 2]);
}
/* cout<<"dp: "<<endl;
for (vi v : dp) {
for (ll x : v)
cout<<x<<" ";
cout<<endl;
}*/
return max(dp[N][0], dp[N][1]);
}
// subtasks 1, 2: greedy
// subtask 3: dp
// code subtask 3 first to verify correct dp
# | 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... |