結果

問題 No.910 素数部分列
ユーザー tkmst201tkmst201
提出日時 2021-02-16 16:20:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,567 bytes
コンパイル時間 2,479 ms
コンパイル使用メモリ 205,376 KB
実行使用メモリ 5,824 KB
最終ジャッジ日時 2023-10-11 04:32:47
合計ジャッジ時間 7,372 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	// 11, 19, 991
	int ans = 0, s = 0;
	vector<int> v;
	for (char c : S) {
		const int n = c - '0';
		if (n == 3 || n == 5 || n == 7) ++ans;
		else v.emplace_back(n);
	}
	{
		int l = 0, r = v.size();
		vector<bool> done(v.size());
		while (l < r) {
			while (l < N && v[l] != 1) ++l;
			while (r > 0 && v[r - 1] != 9) --r;
			if (l >= r) break;
			++ans;
			done[l++] = done[--r] = true;
		}
		vector<int> nv;
		REP(i, v.size()) if (!done[i]) nv.emplace_back(v[i]);
		swap(v, nv);
	}
	{
		int l1 = 0, l2, r = v.size();
		vector<bool> done(v.size());
		while (l1 < r) {
			while (l1 < N && v[l1] != 9) ++l1;
			l2 = l1 + 1;
			while (l2 < N && v[l2] != 9) ++l2;
			while (r > 0 && v[r - 1] != 1) --r;
			if (l2 >= r) break;
			++ans;
			done[l1] = done[l2] = done[--r] = true;
			l1 = l2 + 1;
		}
		int one = 0;
		REP(i, v.size()) if (!done[i] && v[i] == 1) ++one;
		ans += one / 2;
	}
	cout << ans << endl;
}
0