結果
| 問題 | 
                            No.910 素数部分列
                             | 
                    
| コンテスト | |
| ユーザー | 
                             rtia_iidx
                         | 
                    
| 提出日時 | 2019-10-18 22:30:02 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 4,426 bytes | 
| コンパイル時間 | 1,555 ms | 
| コンパイル使用メモリ | 123,944 KB | 
| 最終ジャッジ日時 | 2025-01-07 23:13:37 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 16 WA * 34 | 
ソースコード
#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'){
            ans++;
        }else if(str[i] == '1'){
            st1.insert(i);
        }else if(str[i] == '5'){
            st2.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 = 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;
        }
    }
    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;
        }
    }
    cerr << st1.size() << endl;
    cerr << st2.size() << endl;
    cerr << st3.size() << endl;
    cout << ans << endl;
    return 0;
}
            
            
            
        
            
rtia_iidx