結果

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

ソースコード

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;
        }
    }

    int c1 = 0, c9 = 0;
    for (char c : s) {
        if (c == '1') {
            ++c1;
        } else {
            if (c1 > 0) {
                ++ans;
                --c1;
            } else {
                ++c9;
            }
        }
    }

    ans += c1 / 2;
    c1 %= 2;
    if (c1 == 1 && c9 >= 2) ++ans;

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}
0