結果

問題 No.910 素数部分列
ユーザー hiro71687k
提出日時 2023-04-12 17:18:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 722 bytes
コンパイル時間 3,631 ms
コンパイル使用メモリ 250,668 KB
最終ジャッジ日時 2025-02-12 05:17:02
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=1444999999999999;
ll mod=998244353;
int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    ll x=0,y=0;
    for (ll i = 0; i < s.size(); i++)
    {
        if (s[i]=='3'||s[i]=='5'||s[i]=='7')
        {
            ans+=1;
        }else if (s[i]=='1')
        {
            x+=1;
        }else{
            if (x>0)
            {
                ans+=1;
                x-=1;
            }else{
                y+=1;
            }
        }
    }
    ans+=min(y/2,x);
    x-=min(y/2,x);
    ans+=x/2;
    cout << ans << endl;
}
0