結果

問題 No.910 素数部分列
ユーザー outlineoutline
提出日時 2020-03-14 19:25:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 1,000 ms
コード長 1,797 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 120,940 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-05-03 01:28:14
合計ジャッジ時間 3,001 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 13 ms
6,944 KB
testcase_24 AC 12 ms
6,940 KB
testcase_25 AC 13 ms
6,944 KB
testcase_26 AC 14 ms
6,940 KB
testcase_27 AC 13 ms
6,940 KB
testcase_28 AC 13 ms
6,944 KB
testcase_29 AC 27 ms
8,428 KB
testcase_30 AC 27 ms
8,576 KB
testcase_31 AC 26 ms
8,312 KB
testcase_32 AC 27 ms
8,512 KB
testcase_33 AC 29 ms
8,532 KB
testcase_34 AC 28 ms
8,704 KB
testcase_35 AC 29 ms
8,940 KB
testcase_36 AC 29 ms
8,952 KB
testcase_37 AC 34 ms
9,344 KB
testcase_38 AC 30 ms
9,344 KB
testcase_39 AC 32 ms
9,472 KB
testcase_40 AC 31 ms
9,660 KB
testcase_41 AC 33 ms
9,728 KB
testcase_42 AC 30 ms
9,940 KB
testcase_43 AC 35 ms
9,956 KB
testcase_44 AC 35 ms
9,940 KB
testcase_45 AC 35 ms
9,664 KB
testcase_46 AC 31 ms
9,660 KB
testcase_47 AC 36 ms
9,344 KB
testcase_48 AC 56 ms
12,928 KB
testcase_49 AC 4 ms
6,944 KB
testcase_50 AC 4 ms
6,944 KB
testcase_51 AC 3 ms
6,944 KB
testcase_52 AC 36 ms
8,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    queue<int> One;
    set<int> Nine;
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == '3' || s[i] == '5' || s[i] == '7')   ++ans;
        else if(s[i] == '9')    Nine.insert(i);
        else    One.push(i);
    }
    int OneCnt = 0, NineCnt = 0;
    int left = 0;
    while(!One.empty()){
        int pos = One.front();
        One.pop();
        auto it = Nine.lower_bound(pos);
        if(it != Nine.end()){
            ++ans;
            Nine.erase(*it);
        }
        else{
            ++OneCnt;
            left = pos;
        }
    }
    for(auto it : Nine){
        if(it < left)   ++NineCnt;
    }
    ans += min(NineCnt / 2, OneCnt);
    OneCnt -= min(NineCnt / 2, OneCnt);
    ans += OneCnt / 2;

    cout << ans << endl;
}
0