結果

問題 No.910 素数部分列
ユーザー rok_dwrok_dw
提出日時 2020-03-21 06:51:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 324 ms / 1,000 ms
コード長 2,080 bytes
コンパイル時間 1,682 ms
コンパイル使用メモリ 170,320 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-22 17:48:38
合計ジャッジ時間 7,121 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 11 ms
4,376 KB
testcase_28 AC 10 ms
4,380 KB
testcase_29 AC 15 ms
4,380 KB
testcase_30 AC 16 ms
4,384 KB
testcase_31 AC 15 ms
4,384 KB
testcase_32 AC 15 ms
4,376 KB
testcase_33 AC 24 ms
4,380 KB
testcase_34 AC 28 ms
4,380 KB
testcase_35 AC 30 ms
4,376 KB
testcase_36 AC 120 ms
4,376 KB
testcase_37 AC 73 ms
4,380 KB
testcase_38 AC 143 ms
4,376 KB
testcase_39 AC 121 ms
4,380 KB
testcase_40 AC 265 ms
4,376 KB
testcase_41 AC 151 ms
4,380 KB
testcase_42 AC 323 ms
4,376 KB
testcase_43 AC 215 ms
4,380 KB
testcase_44 AC 192 ms
4,376 KB
testcase_45 AC 154 ms
4,380 KB
testcase_46 AC 140 ms
4,376 KB
testcase_47 AC 99 ms
4,380 KB
testcase_48 AC 6 ms
4,376 KB
testcase_49 AC 6 ms
4,376 KB
testcase_50 AC 6 ms
4,376 KB
testcase_51 AC 4 ms
4,380 KB
testcase_52 AC 324 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;

    string s;
    //string tmp;
    queue<char> q;
    int ans = 0;
    REP(i,n){
        char c;
        cin>>c;
        if(c=='3'||c=='5'||c=='7'){
            ans++;
            continue;
        }
        s += c;
    }
    if(s==""){
        cout << ans << endl;
        return 0;
    }
    
    string ss="";
    bool found19=false;
    do{
        found19=false;
        ss=s[0];
        FOR(i,1,s.size()){
            ss += s[i];
            if(ss[ss.size()-2]=='1' && ss[ss.size()-1]=='9'){
                found19=true;
                ss = ss.substr(0,ss.size()-2);
                ans++;
            }
        }
        s=ss;
    }while(found19);

    int cnt1=0;
    int cnt9=0;
    REP(i,s.size()){
        if(s[i]=='1') cnt1++;
        if(s[i]=='9') cnt9++;
    }

    //DEBUG2(cnt1,cnt9);

    string tmp ="";
    FORR(i,1,s.size()){
        if(s[i]!='1') continue;

        tmp ="";
        FORR(j,0,i){
            if(s[j]=='9'){
                if(tmp.size()==2){
                    ans+=1;
                    cnt1-=1;
                    cnt9-=2;
                    tmp="";
                    break;
                }
                else
                    tmp+="9";
            }   
        }

        if(cnt9<2) break;
    }

    //DEBUG2(cnt1,cnt9);
    
    ans += cnt1/2;

    cout << ans << endl;
    return 0;
}
0