結果

問題 No.910 素数部分列
ユーザー rtia_iidxrtia_iidx
提出日時 2019-10-18 22:50:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,405 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 107,708 KB
実行使用メモリ 13,080 KB
最終ジャッジ日時 2023-09-08 00:57:28
合計ジャッジ時間 4,058 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 45 ms
12,724 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 AC 58 ms
12,848 KB
testcase_49 AC 64 ms
12,744 KB
testcase_50 AC 63 ms
12,728 KB
testcase_51 AC 3 ms
4,380 KB
testcase_52 AC 58 ms
12,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0)return a;
    return mygcd(b,a%b);
}

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

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

    string str;

    cin >> str;

    set<ll> st1,st2,st3;

    ll ans = 0;

    for(int i = 0; i < n; i++){
        if(str[i] == '3' || str[i] == '7' || str[i] == '5'){
            ans++;
        }else if(str[i] == '1'){
            st1.insert(i);
        }else{
            st3.insert(i);
        }
    }

    /*while(true){
        auto itr = st2.begin();
        if(itr == st2.end())break;
        auto r = st3.upper_bound(*itr);
        if(r != st3.end()){
            ans++;
            st2.erase(itr);
            st3.erase(r);
        }else{
            break;
        }
    }*/

    while(true){
        auto itr = st3.begin();
        if(itr == st3.end()){
            break;
        }
        bool check = true;
        auto m = st3.upper_bound(*itr);
        if(m != st3.end()){
            auto r = st1.upper_bound(*m);
            if(r != st1.end()){
                ans++;
                st3.erase(itr);
                st1.erase(r);
                st3.erase(m);
            }else{
                check = false;
            }
        }else{
            break;
        }
        if(!check){
            break;
        }
    }

    while(true){
        auto itr = st1.begin();
        if(itr == st1.end()){
            break;
        }
        auto r = st3.upper_bound(*itr);
        if(r != st3.end()){
            ans++;
            st1.erase(itr);
            st3.erase(r);
        }else{
            break;
        }
    }

    while(true){
        auto itr = st1.begin();
        if(itr == st1.end()){
            break;
        }
        auto r = st1.upper_bound(*itr);
        if(r != st1.end()){
            ans++;
            st1.erase(itr);
            st1.erase(r);
        }else{
            break;
        }
    }

    cerr << ans << endl;

    /*while(true){
        auto itr = st1.begin();
        if(itr == st1.end()){
            break;
        }
        bool check = true;
        auto m = st2.upper_bound(*itr);
        if(m != st2.end()){
            auto r = st1.upper_bound(*m);
            if(r != st1.end()){
                ans++;
                st1.erase(itr);
                st1.erase(r);
                st2.erase(m);
            }else{
                check = false;
            }
        }else{
            break;
        }
        if(!check){
            break;
        }
    }*/

    /*while(true){
        auto itr = st3.begin();
        if(itr == st3.end()){
            break;
        }
        bool check = true;
        auto m = st1.upper_bound(*itr);
        if(m != st1.end()){
            auto r = st1.upper_bound(*m);
            if(r != st1.end()){
                ans++;
                st3.erase(itr);
                st1.erase(r);
                st1.erase(m);
            }else{
                check = false;
            }
        }else{
            break;
        }
        if(!check){
            break;
        }
    }*/

    /*while(true){
        auto itr = st3.begin();
        if(itr == st3.end()){
            break;
        }
        bool check = true;
        auto m = st1.upper_bound(*itr);
        if(m != st1.end()){
            auto r = st3.upper_bound(*m);
            if(r != st3.end()){
                ans++;
                st3.erase(itr);
                st3.erase(r);
                st1.erase(m);
            }else{
                check = false;
            }
        }else{
            break;
        }
        if(!check){
            break;
        }
    }*/

    

    cerr << st1.size() << endl;
    cerr << st2.size() << endl;
    cerr << st3.size() << endl;

    cout << ans << endl;

    return 0;
}
0