結果

問題 No.910 素数部分列
ユーザー koyoprokoyopro
提出日時 2020-02-29 23:04:04
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,797 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 164,616 KB
実行使用メモリ 12,476 KB
最終ジャッジ日時 2024-04-21 21:56:52
合計ジャッジ時間 8,149 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 489 ms
5,376 KB
testcase_24 AC 510 ms
5,376 KB
testcase_25 AC 507 ms
5,376 KB
testcase_26 AC 506 ms
5,376 KB
testcase_27 AC 496 ms
5,376 KB
testcase_28 AC 536 ms
5,376 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);
    }
    while(T.size()) {
        auto it1 = find(ALL(T), 1);
        if (it1 == T.end()) break;
        auto it9 = find(it1, T.end(), 9);
        if (it9 == T.end()) break;
        ans++;
        T.erase(it9);
        T.erase(it1);
    }
    while(T.size()) {
        auto it90 = find(T.begin(), T.end(), 9);
        if (it90 == T.end()) break;
        auto it91 = find(it90+1, T.end(), 9);
        if (it91 == T.end()) break;
        auto it1 = find(it91, T.end(), 1);
        if (it1 == T.end()) break;
        ans++;
        T.erase(it1);
        T.erase(it91);
        T.erase(it90);
    }
    ans += count(ALL(T), 1)/2;
    
    cout << ans << endl;
}
0