結果

問題 No.910 素数部分列
コンテスト
ユーザー minato
提出日時 2019-12-24 20:34:49
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,124 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,187 ms
コンパイル使用メモリ 190,980 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-10 17:33:24
合計ジャッジ時間 2,750 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	string S; cin >> S;

	int count = 0;
	string T = "";
	rep(i,N) {
		if (S[i] == '1' || S[i] == '9') T += S[i];
		else count++;
	}
	int M = T.size();
	int cnt1 = 0;
	int cnt9 = 0;
	for (int i = M-1; i >= 0; i--) {
        if (T[i] == '9') cnt9++;
		else if (cnt9 > 0) {
			cnt9--;
            count++;
		} else {
			cnt1++;
		}
	}
	while (cnt9 > 3 && cnt1 > 0) {
		count++;
		cnt9 -= 4;
		cnt1--;
	}
	count += (cnt1/2);

	cout << count << endl;
}
0