結果

問題 No.910 素数部分列
ユーザー treeone
提出日時 2019-09-03 22:41:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 751 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 194,780 KB
最終ジャッジ日時 2025-01-07 16:25:22
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = "";
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '3' || s[i] == '5' || s[i] == '7') ans++;
        else t += s[i];
    }
    int m = t.size();
    int preone = 0;
    int prenine = 0;
    for(int i = 0; i < m; i++){
        if(t[i] == '1'){
            if(prenine <= 1){
                preone++;
            }else{
                prenine -= 2;
                ans++;
            }
        }else{
            if(preone != 0){
                preone--;
                ans++;
            }else{
                prenine++;
            }
        }
    }
    ans += preone / 2;
    cout << ans << endl;
}
0