結果
問題 | No.291 黒い文字列 |
ユーザー | pekempey |
提出日時 | 2015-10-16 23:25:19 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 196 ms / 2,000 ms |
コード長 | 2,455 bytes |
コンパイル時間 | 1,226 ms |
コンパイル使用メモリ | 147,324 KB |
実行使用メモリ | 95,768 KB |
最終ジャッジ日時 | 2023-09-29 01:52:19 |
合計ジャッジ時間 | 5,317 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
95,212 KB |
testcase_01 | AC | 47 ms
95,272 KB |
testcase_02 | AC | 54 ms
95,412 KB |
testcase_03 | AC | 48 ms
95,144 KB |
testcase_04 | AC | 47 ms
95,132 KB |
testcase_05 | AC | 51 ms
95,204 KB |
testcase_06 | AC | 52 ms
95,088 KB |
testcase_07 | AC | 48 ms
95,212 KB |
testcase_08 | AC | 51 ms
95,196 KB |
testcase_09 | AC | 48 ms
95,088 KB |
testcase_10 | AC | 64 ms
95,088 KB |
testcase_11 | AC | 78 ms
95,080 KB |
testcase_12 | AC | 73 ms
95,408 KB |
testcase_13 | AC | 46 ms
95,136 KB |
testcase_14 | AC | 51 ms
95,144 KB |
testcase_15 | AC | 50 ms
95,268 KB |
testcase_16 | AC | 146 ms
95,304 KB |
testcase_17 | AC | 152 ms
95,576 KB |
testcase_18 | AC | 149 ms
95,276 KB |
testcase_19 | AC | 174 ms
95,720 KB |
testcase_20 | AC | 175 ms
95,640 KB |
testcase_21 | AC | 109 ms
95,212 KB |
testcase_22 | AC | 154 ms
95,628 KB |
testcase_23 | AC | 196 ms
95,768 KB |
testcase_24 | AC | 146 ms
95,560 KB |
testcase_25 | AC | 105 ms
95,148 KB |
testcase_26 | AC | 107 ms
95,148 KB |
testcase_27 | AC | 77 ms
95,144 KB |
testcase_28 | AC | 97 ms
95,184 KB |
testcase_29 | AC | 99 ms
95,140 KB |
ソースコード
#include <bits/stdc++.h> #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) using namespace std; typedef long long ll; #include <bits/stdc++.h> #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) #define chmin(a, b) ((b) < a && (a = (b), true)) #define chmax(a, b) (a < (b) && (a = (b), true)) using namespace std; typedef long long ll; int dp[101][22][22][22][22]; // pos, k, u, r, o => i int main() { string s; cin >> s; int N = s.length(); const int inf = 1e9; rep (i, 101) rep (j, 21) rep (k, 21) rep (l, 21) rep (m, 21) dp[i][j][k][l][m] = -inf; dp[0][0][0][0][0] = 0; rep (i, N) rep (j, 21) rep (k, 21) rep (l, 21) rep (m, 21) { chmax(dp[i + 1][j][k][l][m], dp[i][j][k][l][m]); if (s[i] == 'K') { chmax(dp[i + 1][j + 1][k][l][m], dp[i][j][k][l][m]); } else if (s[i] == 'U') { if (j) chmax(dp[i + 1][j - 1][k + 1][l][m], dp[i][j][k][l][m]); } else if (s[i] == 'R') { if (k) chmax(dp[i + 1][j][k - 1][l + 1][m], dp[i][j][k][l][m]); } else if (s[i] == 'O') { if (l) chmax(dp[i + 1][j][k][l - 1][m + 1], dp[i][j][k][l][m]); } else if (s[i] == 'I') { if (m) chmax(dp[i + 1][j][k][l][m - 1], dp[i][j][k][l][m] + 1); } else if (s[i] == '?') { chmax(dp[i + 1][j + 1][k][l][m], dp[i][j][k][l][m]); if (j) chmax(dp[i + 1][j - 1][k + 1][l][m], dp[i][j][k][l][m]); if (k) chmax(dp[i + 1][j][k - 1][l + 1][m], dp[i][j][k][l][m]); if (l) chmax(dp[i + 1][j][k][l - 1][m + 1], dp[i][j][k][l][m]); if (m) chmax(dp[i + 1][j][k][l][m - 1], dp[i][j][k][l][m] + 1); } } int ans = 0; rep (j, 21) rep (k, 21) rep (l, 21) rep (m, 21) { chmax(ans, dp[N][j][k][l][m]); } cout << ans << endl; return 0; }