結果

問題 No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん
ユーザー SSRS
提出日時 2021-06-06 18:49:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 752 bytes
コンパイル時間 1,800 ms
コンパイル使用メモリ 173,488 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-23 03:45:43
合計ジャッジ時間 2,589 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 100000;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  string T = "ponpon";
  vector<vector<int>> dp(N + 1, vector<int>(7, -INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= 6; j++){
      if (dp[i][j] != -INF){
        if (S[i] == T[dp[i][j] % 3]){
          dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1);
        } else {
          dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
        if (j < 6){
          if (S[i] == T[j]){
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] / 3 * 3);
          }
        }
      }
    }
  }
  if (dp[N][6] == -INF){
    cout << -1 << endl;
  } else {
    cout << dp[N][6] / 3 << endl;
  }
}
0