結果

問題 No.910 素数部分列
ユーザー yakkiyakki
提出日時 2019-10-18 21:58:37
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 87,060 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 15:59:39
合計ジャッジ時間 2,138 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    int now1 = 0;
    int now9 = 0;
    rep(i,N){
        if(S[i] == '3' || S[i] == '5' || S[i] == '7') ans++;
        if(S[i] == '1'){
            now1++;
            if(now1 >= 2){
                now1 -= 2;
                ans++;
            }
            else if(now9 >= 2){
                now1--;
                now9 -= 2;
                ans++;
            }
        }
        if(S[i] == '9'){
            now9++;
            if(now1 > 0){
                now1--;
                now9--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}
0