結果

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

ソースコード

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;

  dp[n] = 0;
  for (int i = n-1; i >= 0; i--) {
    int x = s[i] - '0';
    dp[i] = dp[i+1];
    if (x == 3 || x == 5 || x == 7)
      dp[i] = dp[i+1] + 1;
    else if (x == 1) {
      if (i+2 <= n)
        dp[i] = max(dp[i], dp[i+2] + 1);
    } else {
      dp[i] = dp[i+1];
    }
  }
  cout << dp[0] << endl;
  
  return 0;
}
0