結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt9=0;
    ll cnt1=0;
    ll ans=0;
    reverse(all(s));
    rep(i,n){
        if(s[i]=='9'){
            cnt9++;
            if(cnt9==2&&cnt1==1){
                ans++;
                cnt9=0;
                cnt1=0;
            }
        }
        else if(s[i]=='1'){
            if(cnt9){
                ans++;
                cnt9--;
            }else{
                cnt1++;
            }
        }else{
            ans++;
        }
    }
    ans+=cnt1/2;
    cout<<ans<<endl;
}
0