結果
| 問題 |
No.910 素数部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-18 19:30:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 713 bytes |
| コンパイル時間 | 3,799 ms |
| コンパイル使用メモリ | 196,288 KB |
| 最終ジャッジ日時 | 2025-01-18 22:34:37 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
cin >> n >> s;
int ret = 0;
stack<int> stk;
for (int i = 0; i < n; i++) {
char c = s[i];
if (c == '1') {
stk.push(1);
} else if (c == '9') {
if (!stk.empty() && stk.top() == 1) {
stk.pop();
++ret;
} else {
stk.push(9);
}
} else {
++ret;
}
}
int one = 0;
int nine = 0;
while (!stk.empty()) {
if (stk.top() == 1)
++one;
else
++nine;
stk.pop();
}
ret += min(one, nine / 2);
one -= min(one, nine / 2);
ret += one / 2;
cout << ret << endl;
return 0;
}