結果
| 問題 |
No.910 素数部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-19 18:31:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 1,000 ms |
| コード長 | 1,082 bytes |
| コンパイル時間 | 1,643 ms |
| コンパイル使用メモリ | 166,788 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-27 14:39:05 |
| 合計ジャッジ時間 | 3,203 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
string S;
cin >> S;
// 11, 19, 991 を何個とることができるかを考える。
int count1 = 0;
int count1deleted = 0;
int ans = N;
for (char &s : S){
if (s == '1'){
++count1;
--ans;
}else if (s == '9'){
--ans;
if (count1 > 0){
--count1;
++count1deleted;
++ans;
s = '0';
}
}
}
for (char &s : S){
if (s == '1' and count1deleted > 0){
--count1deleted;
s = '0';
if (count1deleted == 0) break;
}
}
int count9 = 0;
for (char &s : S){
if (s == '1'){
if (count9 >= 2){
count9 -= 2;
++ans;
--count1;
}
}else if (s == '9'){
++count9;
}
}
cout << ans + count1 / 2 << endl;
return 0;
}