結果

問題 No.910 素数部分列
ユーザー wk1080idwk1080id
提出日時 2019-10-18 21:58:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,056 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 91,700 KB
実行使用メモリ 12,996 KB
最終ジャッジ日時 2023-09-07 22:23:43
合計ジャッジ時間 4,575 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 24 ms
7,128 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 52 ms
12,580 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 53 ms
12,904 KB
testcase_35 AC 55 ms
12,892 KB
testcase_36 AC 54 ms
12,728 KB
testcase_37 AC 60 ms
12,788 KB
testcase_38 AC 57 ms
12,880 KB
testcase_39 AC 59 ms
12,744 KB
testcase_40 AC 59 ms
12,744 KB
testcase_41 AC 60 ms
12,988 KB
testcase_42 AC 56 ms
12,816 KB
testcase_43 AC 59 ms
12,740 KB
testcase_44 AC 57 ms
12,904 KB
testcase_45 AC 58 ms
12,796 KB
testcase_46 AC 54 ms
12,796 KB
testcase_47 AC 59 ms
12,872 KB
testcase_48 AC 59 ms
12,820 KB
testcase_49 AC 61 ms
12,728 KB
testcase_50 AC 62 ms
12,820 KB
testcase_51 AC 6 ms
4,380 KB
testcase_52 AC 63 ms
12,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    string s;
    cin >> s;
    //11,19,991
    int ans = 0;
    set<int> a,b;//1,9
    rep(i,n){
        switch (s[i]) {
            case '1': a.insert(i);break;
            case '9': b.insert(i);break;
            case '3':;
            case '5':;
            case '7':ans++;break;
        }
    }
    //cout << ans << endl;
    //for(auto x: a)cout << " "<< x;cout << endl;
    //for(auto x: b)cout << " "<< x;cout << endl;
    int p = 0, q = 0;
    int cnt = 0;
    for(auto x: a){
        auto itr = b.lower_bound(x);
        int num1 = *itr;
        if(itr == b.end()){
            if(itr == b.begin() /* 9が存在しない*/
                || (--itr == b.begin()) /*前に9が1つの場合*/){
                    cnt++;
                    continue;
            }
            int num2 = *itr;
            //前に9が2つあるので削除
            ans++;//991
            b.erase(num1);
            b.erase(num2);
        }else{
            ans++;//19
            b.erase(num1);
        }
    }
    ans += cnt/2;
    cout << ans << endl;
}
0