結果
問題 | No.1542 ぽんぽんぽん ぽんぽんぽんぽん ぽんぽんぽん |
ユーザー | SSRS |
提出日時 | 2021-06-06 19:06:45 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,033 bytes |
コンパイル時間 | 1,580 ms |
コンパイル使用メモリ | 169,896 KB |
実行使用メモリ | 4,592 KB |
最終ジャッジ日時 | 2023-08-15 02:09:01 |
合計ジャッジ時間 | 6,879 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | AC | 2 ms
4,380 KB |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; string S; cin >> S; vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0)); for (int i = N; i >= 0; i--){ for (int j = i + 1; j <= N; j++){ if (S[i] == 'p' && S[j - 1] == 'n'){ for (int k = i + 1; k < j - 1; k++){ if (S[k] == 'o'){ dp[i][j] = max(dp[i][j], dp[i + 1][k] + dp[k + 1][j - 1] + 1); } } dp[i][j] = max(dp[i][j], dp[i + 1][j]); dp[i][j] = max(dp[i][j], dp[i][j - 1]); } } } S += '$'; N++; string T = "ponpon$"; vector<vector<int>> dp2(N + 1, vector<int>(8, -1)); dp2[0][0] = 0; for (int i = 0; i < N; i++){ for (int j = i; j < N; j++){ for (int k = 0; k < 7; k++){ if (dp2[i][k] != -1 && S[j] == T[k]){ dp2[j + 1][k + 1] = max(dp2[j + 1][k + 1], dp2[i][k] + dp[i][j]); } } } } if (dp2[N][7] == -1){ cout << -1 << endl; } else { assert(false); cout << dp2[N][7] << endl; } }