結果
| 問題 |
No.910 素数部分列
|
| コンテスト | |
| ユーザー |
minato
|
| 提出日時 | 2019-12-24 20:34:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,124 bytes |
| コンパイル時間 | 1,983 ms |
| コンパイル使用メモリ | 177,248 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-22 11:30:10 |
| 合計ジャッジ時間 | 3,524 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 WA * 11 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
///////////////////////////////////////////////////////////////
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N; cin >> N;
string S; cin >> S;
int count = 0;
string T = "";
rep(i,N) {
if (S[i] == '1' || S[i] == '9') T += S[i];
else count++;
}
int M = T.size();
int cnt1 = 0;
int cnt9 = 0;
for (int i = M-1; i >= 0; i--) {
if (T[i] == '9') cnt9++;
else if (cnt9 > 0) {
cnt9--;
count++;
} else {
cnt1++;
}
}
while (cnt9 > 3 && cnt1 > 0) {
count++;
cnt9 -= 4;
cnt1--;
}
count += (cnt1/2);
cout << count << endl;
}
minato