結果
| 問題 | No.910 素数部分列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-25 01:14:32 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 14 ms / 1,000 ms |
| + 944µs | |
| コード長 | 922 bytes |
| 記録 | |
| コンパイル時間 | 1,931 ms |
| コンパイル使用メモリ | 187,228 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-11-25 01:14:38 |
| 合計ジャッジ時間 | 5,539 ms |
|
ジャッジサーバーID (参考情報) |
judge6_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
string s;
int n, ans, rem1;
vector<int> pos1, pos9;
int main() {
scanf("%d", &n);
for (int i = 0, x; i < n; ++i) {
scanf(" %1d", &x);
if (x == 3 || x == 5 || x == 7) {
++ans;
} else s += '0' + x;
}
n = s.size();
s = ' ' + s;
for (int i = 1; i <= n; ++i) {
if (s[i] == '1') pos1.push_back(i);
else pos9.push_back(i);
}
int rem9 = pos9.size();
auto it = pos9.begin();
for (auto i : pos1) {
auto pos = lower_bound(it, pos9.end(), i);
if (pos < pos9.end()) {
++ans;
--rem9;
it = next(pos);
} else ++rem1;
}
int cnt = min(rem1, rem9 / 2);
ans += cnt;
rem1 -= cnt;
printf("%d\n", ans + rem1 / 2);
return 0;
}