結果

問題 No.910 素数部分列
ユーザー first_vilfirst_vil
提出日時 2019-10-18 22:27:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,935 bytes
コンパイル時間 1,571 ms
コンパイル使用メモリ 166,336 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-08 00:17:52
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n; cin >> n;
    string s; cin >> s;

    int itr = -1, ans = 0;
    FOR(i, 0, n) {
        if (s[i] == '1')itr = i;
        else if (0 <= itr && s[i] == '9') {
            s[itr] = 'x';
            s[i] = 'x';
            ans++;
            itr = -1;
        }
    }

    int itr2 = -1;
    itr = -1;
    FOR(i, 0, n) {
        if (itr < 0) {
            if (s[i] == '9')itr = i;
        }
        else if (itr2 < 0) {
            if (s[i] == '9')itr2 = i;
        }
        else if (s[i] == '1') {
            s[itr] = 'x';
            s[itr2] = 'x';
            s[i] = 'x';
            ans++;
        }
    }

    int cnt = 0;
    FOR(i, 0, n) {
        if (s[i] == '1') {
            cnt++;
            s[i] = 'x';
        }
        else if (s[i] == '9')s[i] = 'x';
    }
    ans += cnt / 2;

    FOR(i, 0, n) {
        if (s[i] != 'x')ans++;
    }
    cout << ans << "\n";
}
0