結果

問題 No.910 素数部分列
ユーザー ei1333333
提出日時 2019-09-04 00:25:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 1,000 ms
コード長 410 bytes
コンパイル時間 2,052 ms
コンパイル使用メモリ 194,120 KB
最終ジャッジ日時 2025-01-07 16:25:41
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int one = 0, nine = 0, ret = 0;
  for(auto &c : S) {
    if(c == '3' || c == '5' || c == '7') {
      ++ret;
    } else if(c == '1') {
      ++one;
    } else {
      if(one > 0) --one, ++ret;
      else ++nine;
    }
  }
  int v = min(nine / 2, one);
  one -= v;
  cout << ret + v + one / 2 << endl;
}
0