結果

問題 No.910 素数部分列
ユーザー rogi52rogi52
提出日時 2022-10-12 23:00:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 799 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 203,824 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-08 18:41:05
合計ジャッジ時間 4,755 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 24 ms
4,380 KB
testcase_25 AC 24 ms
4,380 KB
testcase_26 AC 25 ms
4,376 KB
testcase_27 AC 24 ms
4,380 KB
testcase_28 AC 25 ms
4,380 KB
testcase_29 AC 23 ms
4,384 KB
testcase_30 AC 24 ms
4,380 KB
testcase_31 AC 24 ms
4,380 KB
testcase_32 AC 24 ms
4,376 KB
testcase_33 AC 24 ms
4,380 KB
testcase_34 AC 24 ms
4,376 KB
testcase_35 AC 24 ms
4,380 KB
testcase_36 AC 23 ms
4,380 KB
testcase_37 AC 24 ms
4,376 KB
testcase_38 AC 24 ms
4,380 KB
testcase_39 AC 24 ms
4,380 KB
testcase_40 AC 24 ms
4,376 KB
testcase_41 AC 25 ms
4,380 KB
testcase_42 AC 25 ms
4,376 KB
testcase_43 AC 25 ms
4,380 KB
testcase_44 AC 25 ms
4,380 KB
testcase_45 AC 25 ms
4,380 KB
testcase_46 AC 25 ms
4,380 KB
testcase_47 AC 25 ms
4,384 KB
testcase_48 AC 24 ms
4,388 KB
testcase_49 AC 23 ms
4,384 KB
testcase_50 AC 23 ms
4,380 KB
testcase_51 AC 23 ms
4,376 KB
testcase_52 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    // 3, 5, 7
    // 19, 11, 991
    int N; string S; cin >> N >> S;
    int ans = 0, c1 = 0;
    string T = "";
    rep(i,N) {
        if(set<int>{3, 5, 7}.count(S[i] - '0')) ans++;
        if(S[i] == '1') c1++;
        if(S[i] == '9') {
            if(c1 == 0) T += S[i];
            else c1--, ans++;
        }
    }

    int c9 = 0;
    for(char c : T) if(c == '9') c9++;

    {
        int ANS = 0;
        for(int a1 = 0; a1 <= c1 / 2; a1++) {
            int r1 = c1 - a1 * 2;
            int a9 = min(c9 / 2, r1);
            ANS = max(ANS, a1 + a9);
        }
        ans += ANS;
    }
    cout << ans << endl;
}
0