結果

問題 No.910 素数部分列
ユーザー koyoprokoyopro
提出日時 2020-02-29 23:45:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,384 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 163,296 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-21 21:58:00
合計ジャッジ時間 8,402 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,948 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 498 ms
6,940 KB
testcase_24 AC 510 ms
6,940 KB
testcase_25 AC 505 ms
6,940 KB
testcase_26 AC 506 ms
6,940 KB
testcase_27 AC 494 ms
6,940 KB
testcase_28 AC 538 ms
6,944 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int N,M,Q;
string S;

void solve() {
    cin>>N>>S;

    int ans = 0;
    ans += count(ALL(S), '3');
    ans += count(ALL(S), '5');
    ans += count(ALL(S), '7');
    vector<int> T;
    for (char c:S) {
        int i = c-'0';
        if (i == 1 || i == 9) T.push_back(i);
    }
    int i1=0, i90=0, i91=0;
    while(T.size()) {
        while(i1<T.size()) {
            if (T[i1] == 1) break;
            i1++;
        }
        if (i1 >= T.size()) break;
        i90 = max(i90, i1+1);
        while(i90<T.size()) {
            if (T[i90] == 9) break;
            i90++;
        }
        if (i90 >= T.size()) break;
        ans++;
        T.erase(T.begin() + i90);
        T.erase(T.begin() + i1);
        i90 = max(0LL, i90-2);
        i1 = max(0LL, i1-2);
    }
    i1 = i90 = 0;
    while(T.size()) {
        while(i90<T.size()) {
            if (T[i90] == 9) break;
            i90++;
        }
        if (i90 >= T.size()) break;
        i91 = i90 + 1;
        while(i91<T.size()) {
            if (T[i91] == 9) break;
            i91++;
        }
        if (i91 >= T.size()) break;
        i1 = max(i1, i91);
        while(i1<T.size()) {
            if (T[i1] == 1) break;
            i1++;
        }
        if (i1 >= T.size()) break;
        ans++;
        T.erase(T.begin() + i1);
        T.erase(T.begin() + i91);
        T.erase(T.begin() + i90);
        i90 = max(0LL, i90-3);
        i91 = max(0LL, i91-3);
        i1 = max(0LL, i1-3);
    }
    ans += count(ALL(T), 1)/2;
    
    cout << ans << endl;
}
0