結果

問題 No.910 素数部分列
ユーザー Mister
提出日時 2020-05-02 00:54:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 874 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 73,820 KB
最終ジャッジ日時 2025-01-10 05:41:29
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

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

    int ans = 0;
    std::string s;
    while (n--) {
        char c;
        std::cin >> c;
        if (c == '1' || c == '9') {
            s.push_back(c);
        } else {
            ++ans;
        }
    }

    n = s.length();
    std::vector<int> dp(n + 1, 0);
    dp[0] = ans;
    for (int i = 0; i < n; ++i) {
        dp[i + 1] = std::max(dp[i + 1], dp[i]);
        if (s.substr(i, 2) == "11" ||
            s.substr(i, 2) == "19") {
            dp[i + 2] = std::max(dp[i + 2], dp[i] + 1);
        }
        if (s.substr(i, 3) == "991") {
            dp[i + 3] = std::max(dp[i + 3], dp[i] + 1);
        }
    }

    std::cout << dp.back() << std::endl;
}

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

    solve();

    return 0;
}
0