結果

問題 No.910 素数部分列
コンテスト
ユーザー WutongDeath
提出日時 2026-11-25 01:14:32
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 14 ms / 1,000 ms
+ 944µs
コード長 922 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,931 ms
コンパイル使用メモリ 187,228 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-11-25 01:14:38
合計ジャッジ時間 5,539 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>

using namespace std;

string s;
int n, ans, rem1;
vector<int> pos1, pos9;

int main() {
    scanf("%d", &n);
    for (int i = 0, x; i < n; ++i) {
        scanf(" %1d", &x);
        if (x == 3 || x == 5 || x == 7) {
            ++ans;
        } else s += '0' + x;
    }

    n = s.size();
    s = ' ' + s;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '1') pos1.push_back(i);
        else pos9.push_back(i);
    }

    int rem9 = pos9.size();
    auto it = pos9.begin();
    for (auto i : pos1) {
        auto pos = lower_bound(it, pos9.end(), i);
        if (pos < pos9.end()) {
            ++ans;
            --rem9;
            it = next(pos);
        } else ++rem1;
    }

    int cnt = min(rem1, rem9 / 2);
    ans += cnt;
    rem1 -= cnt;
    printf("%d\n", ans + rem1 / 2);

    return 0;
}
0