結果

問題 No.910 素数部分列
ユーザー k
提出日時 2020-09-05 03:53:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 649 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 195,584 KB
最終ジャッジ日時 2025-01-14 06:55:03
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int dp[200000+1];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  string s;
  cin >> n >> s;

  vector<int> p1, p9;

  int ret = 0;
  REP (i, n) {
    char c = s[i];
    if (c == '1')
      p1.push_back(i);
    else if (c == '9')
      p9.push_back(i);
    else
      ++ret;
  }

  int match = 0;
  int j = p9.size() - 1;
  for (int i = p1.size() - 1; i >= 0 && j >= 0; i--) {
    if (p1[i] < p9[j]) {
      ++match;
      --j;
    }
  }

  ret += match;
  ret += (p1.size() - match) / 2;
  cout << ret << endl;
  
  return 0;
}
0