結果
問題 | No.910 素数部分列 |
ユーザー |
![]() |
提出日時 | 2019-10-18 21:37:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 1,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 1,454 ms |
コンパイル使用メモリ | 167,176 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 21:21:26 |
合計ジャッジ時間 | 2,943 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h>#define rep(i, n) for(int i = 0; i < (int)n; i++)using namespace std;using ll = long long;int main() {int n;string s;cin >> n >> s;int ans = 0;string t = "";rep(i, n) {if(s[i] == '3' || s[i] == '5' || s[i] == '7') {ans++;} else {t += s[i];}}// 11, 19, 991int c1 = 0, c9 = 0;rep(i, t.size()) {if(t[i] == '1') {c1++;} else {if(c1) {c1--;ans++;} else c9++;}}while(c9 >= 2) {if(c1) {c9 -= 2;c1--;ans++;} else break;}while(c1 >= 2) {c1 -= 2;ans++;}cout << ans << endl;return 0;}