結果
問題 |
No.910 素数部分列
|
ユーザー |
|
提出日時 | 2020-05-02 01:04:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 1,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 1,110 ms |
コンパイル使用メモリ | 70,884 KB |
最終ジャッジ日時 | 2025-01-10 05:41:41 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <iostream> #include <vector> #include <string> void solve() { int n; std::cin >> n; int ans = 0; std::string s; while (n--) { char c; std::cin >> c; if (c == '1' || c == '9') { s.push_back(c); } else { ++ans; } } int c1 = 0, c9 = 0; for (char c : s) { if (c == '1') { ++c1; } else { if (c1 > 0) { ++ans; --c1; } else { ++c9; } } } int g = std::min(c1, c9 / 2); ans += g; c1 -= g; ans += c1 / 2; std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }