結果
| 問題 |
No.910 素数部分列
|
| コンテスト | |
| ユーザー |
square1001
|
| 提出日時 | 2019-10-18 21:37:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 980 bytes |
| コンパイル時間 | 680 ms |
| コンパイル使用メモリ | 72,796 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-06-25 15:12:07 |
| 合計ジャッジ時間 | 3,193 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | TLE * 1 -- * 49 |
ソースコード
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int solve(string str) {
int n = str.size();
vector<bool> used(n);
int ans = 0;
int l = 0, r = n - 1;
while (true) {
while (l != n && str[l] == '9') ++l;
while (r != -1 && str[r] == '1') --r;
if (l >= r) break;
used[l] = true, used[r] = true;
++ans;
}
l = 0, r = n - 1;
while (true) {
while (l != n && (used[l] || str[l] == '1')) ++l;
while (l != n && (used[l] || str[l] == '1')) ++l;
while (r != -1 && (used[r] || str[r] == '9')) --r;
if (l >= r) break;
used[r] = true;
++ans;
}
int remc = 0;
for (int i = 0; i < n; ++i) {
if (!used[i] && str[i] == '1') ++remc;
}
ans += remc / 2;
return ans;
}
int main() {
int n;
string s;
cin >> n >> s;
string str;
int ans = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1' || s[i] == '9') {
str += s[i];
}
else {
++ans;
}
}
ans += solve(str);
cout << ans << endl;
return 0;
}
square1001