結果

問題 No.910 素数部分列
ユーザー qsako6
提出日時 2019-10-20 03:38:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 1,000 ms
コード長 670 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 68,104 KB
最終ジャッジ日時 2025-01-08 00:02:48
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int cnt_1 = 0;
  int cnt_9 = 0;
  rep(i, n) {
    if ((s[i] != '1') && (s[i] != '9')) {
      // 3, 5, 7を消す
      ++ans;
    } else if (s[i] == '1') {
      cnt_1++;
    } else if (s[i] == '9') {
      // 19を消す
      cnt_9++;
      if (cnt_1 > 0) {
        cnt_1--;
        cnt_9--;
        ans++;
      }
    }
  }
  int cnt_991 = min(cnt_9 / 2, cnt_1);
  ans += cnt_991;
  ans += (cnt_1 - cnt_991) / 2;
  cout << ans << endl;

  return 0;
}
0