結果

問題 No.910 素数部分列
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-10-19 08:04:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 2,291 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 202,396 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 16:55:31
合計ジャッジ時間 4,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
bool used[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;

	int ans = 0;

	// 3,5,7
	rep(i, 0, N) if (S[i] != '1' and S[i] != '9') {
		used[i] = true;
		ans++;
	}

	// 19
	queue<int> ones;
	rep(i, 0, N) if (!used[i]) {
		if (S[i] == '1') ones.push(i);
		if (S[i] == '9') {
			if (1 <= ones.size()) {
				int one = ones.front(); ones.pop();
				used[one] = true;
				used[i] = true;
				ans++;
			}
		}
	}

	// 991
	queue<int> nines;
	rep(i, 0, N) if (!used[i]) {
		if (S[i] == '9') nines.push(i);
		if (S[i] == '1') {
			if (2 <= nines.size()) {
				int nine1 = nines.front(); nines.pop();
				int nine2 = nines.front(); nines.pop();
				used[nine1] = true;
				used[nine2] = true;
				used[i] = true;
				ans++;
			}
		}
	}

	// 11
	int cnt1 = 0;
	rep(i, 0, N) if (!used[i] and S[i] == '1') cnt1++;
	ans += cnt1 / 2;

	cout << ans << endl;
}





0