結果
問題 |
No.910 素数部分列
|
ユーザー |
|
提出日時 | 2019-10-18 23:45:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 1,000 ms |
コード長 | 1,102 bytes |
コンパイル時間 | 552 ms |
コンパイル使用メモリ | 70,016 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 22:04:16 |
合計ジャッジ時間 | 2,072 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <iostream> #include <string> #include <vector> //1, 3, 5, 7, 11, 19, 991 int main() { int N; std::string s; std::vector<int> a; std::cin >> N; std::cin >> s; int ans = 0; for (int i = 0; i < N; ++i) { if (s[i] != '9' && s[i] != '1') { ++ans; } else { a.push_back(s[i] - '0'); } } // 11, 19, 991 // 99999911111111111 int cnt1 = 0, cnt9 = 0; for (int i = 0; i < a.size(); ++i) { if (a[i] == 9 && cnt1 > 0) { --cnt1; ++ans; } else if (a[i] == 9) { ++cnt9; } else if (a[i] == 1) { ++cnt1; } } int cnt991 = std::min(cnt9 / 2, cnt1); cnt9 -= cnt991 * 2; cnt1 -= cnt991; ans += cnt991 + cnt1 / 2; std::cout << ans << std::endl; }