結果

問題 No.910 素数部分列
ユーザー tekihei2317tekihei2317
提出日時 2019-10-18 22:10:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 168,208 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 17:05:05
合計ジャッジ時間 3,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin>>N;
    string s; cin>>s;
    vector<int> cnt(10);
    for(int i=0;i<N;i++){
        cnt[s[i]-'0']++;
    }

    if(cnt[9]==0){
        cout<<cnt[3]+cnt[5]+cnt[7]+cnt[1]/2<<endl;
    }else{
        int ans=0;
        int c1=0,c9=0;
        for(int i=0;i<N;i++){
            if(s[i]!='1' and s[i]!='9'){
                ans++;
                continue;
            }
            if(s[i]=='1') c1++;
            else{
                if(c1>0) c1--,ans++;
                else c9++;
            }
        }
        // cout<<c1<<' '<<c9<<endl;
        ans+=c1/2;
        if(c1%2==1 and c9>=2) ans++;
        cout<<ans<<endl;
    }
    return 0;
}
0