結果
問題 | No.2196 Pair Bonus |
ユーザー | AnchorBlues |
提出日時 | 2023-03-04 16:53:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 85 ms / 2,000 ms |
コード長 | 1,900 bytes |
コンパイル時間 | 2,171 ms |
コンパイル使用メモリ | 207,308 KB |
実行使用メモリ | 19,024 KB |
最終ジャッジ日時 | 2023-10-18 04:35:19 |
合計ジャッジ時間 | 5,366 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 85 ms
19,024 KB |
testcase_04 | AC | 85 ms
19,024 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 16 ms
5,892 KB |
testcase_09 | AC | 79 ms
17,968 KB |
testcase_10 | AC | 52 ms
12,688 KB |
testcase_11 | AC | 20 ms
6,684 KB |
testcase_12 | AC | 68 ms
15,660 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 9 ms
4,572 KB |
testcase_15 | AC | 2 ms
4,348 KB |
testcase_16 | AC | 74 ms
17,968 KB |
testcase_17 | AC | 3 ms
4,348 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; const ll INF = 1LL << 60; template <class T> void chmax(T& a, T b) { if (b > a) a = b; } template <class T> void chmin(T& a, T b) { if (b < a) a = b; } template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template <typename T> void print_vector(vector<T> a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); ll N; cin >> N; vector<ll> A(2 * N), B(2 * N), X(N), Y(N); for (int i = 0; i < 2 * N; i++) { cin >> A[i]; } for (int i = 0; i < 2 * N; i++) { cin >> B[i]; } for (int i = 0; i < N; i++) { cin >> X[i]; } for (int i = 0; i < N; i++) { cin >> Y[i]; } vector<vector<ll>> dp(2 * N, vector<ll>(2, 0)); dp[0][0] = A[0]; dp[0][1] = B[0]; for (int i = 1; i < 2 * N; i++) { ll a = A[i]; ll b = B[i]; if (i % 2 == 1) { ll x = X[i / 2]; ll y = Y[i / 2]; ll tmp0 = max(dp[i - 1][0] + x, dp[i - 1][1] + y); dp[i][0] = tmp0 + a; ll tmp1 = max(dp[i - 1][0] + y, dp[i - 1][1] + x); dp[i][1] = tmp1 + b; } else { ll tmp = max(dp[i - 1][0], dp[i - 1][1]); dp[i][0] = tmp + a; dp[i][1] = tmp + b; } } std::cout << max(dp[2 * N - 1][0], dp[2 * N - 1][1]) << "\n"; return 0; }