結果

問題 No.910 素数部分列
ユーザー homesentinelhomesentinel
提出日時 2019-11-01 18:29:50
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,625 bytes
コンパイル時間 2,969 ms
コンパイル使用メモリ 119,140 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 00:55:06
合計ジャッジ時間 6,270 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        string S;
        cin >> S;

        vector<bool> used(N, false);
        int ans = 0;

        for (int i = 0; i < N; ++i) {
            if (S[i] == '3' or S[i] == '5' or S[i] == '7') {
                ans++;
                used[i] = true;
            }
        }

        stack<int> st;
        for (int i = 0; i < N; ++i) {
            if (!used[i]) {
                if (st.empty()) {
                    st.push(i);
                } else {
                    if (S[st.top()] == '1' && S[i] == '9') {
                        st.pop();
                        ans++;
                        used[st.top()] = true;
                        used[i] = true;
                    } else {
                        st.push(i);
                    }
                }
            }
        }


        int c1 = 0, c9 = 0;
        for (int i = 0; i < N; ++i) {
            if (!used[i]) {
                if (S[i] == '1') c1++;
                else c9++;
            }
        }

        {
            int dec = min(c9 / 2, c1);
            c1 -= dec;
            c9 -= dec * 2;
            ans += dec;
        }

        {
            int dec = c1 / 2;
            ans += dec;
        }

        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}
0