結果
| 問題 |
No.910 素数部分列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-12 23:00:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 1,000 ms |
| コード長 | 799 bytes |
| コンパイル時間 | 2,047 ms |
| コンパイル使用メモリ | 198,512 KB |
| 最終ジャッジ日時 | 2025-02-08 02:16:56 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
// 3, 5, 7
// 19, 11, 991
int N; string S; cin >> N >> S;
int ans = 0, c1 = 0;
string T = "";
rep(i,N) {
if(set<int>{3, 5, 7}.count(S[i] - '0')) ans++;
if(S[i] == '1') c1++;
if(S[i] == '9') {
if(c1 == 0) T += S[i];
else c1--, ans++;
}
}
int c9 = 0;
for(char c : T) if(c == '9') c9++;
{
int ANS = 0;
for(int a1 = 0; a1 <= c1 / 2; a1++) {
int r1 = c1 - a1 * 2;
int a9 = min(c9 / 2, r1);
ANS = max(ANS, a1 + a9);
}
ans += ANS;
}
cout << ans << endl;
}