結果

問題 No.910 素数部分列
コンテスト
ユーザー 夜
提出日時 2020-11-15 10:13:27
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 6 ms / 1,000 ms
+ 29µs
コード長 727 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 535 ms
コンパイル使用メモリ 111,948 KB
実行使用メモリ 9,848 KB
最終ジャッジ日時 2026-11-15 17:07:45
合計ジャッジ時間 3,168 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	int co = 0, co1 = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] != '1' && s[i] != '9') {
			ans++;
		}
		else if (s[i] == '9') {
			co++;
		}
		else {
			if (co != 0) {
				co--;
				ans++;
			}
			else {
				co1++;
			}
		}
	}
	ans += min(co / 2, co1);
	co1 -= min(co / 2, co1);
	cout << ans + co1 / 2 << endl;
}
0