結果

問題 No.1160 Strange Bowling
ユーザー Mister
提出日時 2020-08-18 06:26:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 73,188 KB
最終ジャッジ日時 2025-01-13 02:50:05
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> dp(2, -INF);
    dp[0] = 0;

    auto ndp = dp;
    while (n--) {
        std::vector<int> ps(2);
        for (auto& p : ps) std::cin >> p;

        std::fill(ndp.begin(), ndp.end(), -INF);
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < 2; ++j) {
                ndp[j] = std::max(ndp[j], dp[i] + ps[j] * (i ? 2 : 1));
            }
        }
        std::swap(dp, ndp);
    }

    std::cout << dp[0] << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0