結果
問題 | No.291 黒い文字列 |
ユーザー | pekempey |
提出日時 | 2015-10-16 23:44:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 171 ms / 2,000 ms |
コード長 | 2,135 bytes |
コンパイル時間 | 1,253 ms |
コンパイル使用メモリ | 147,168 KB |
実行使用メモリ | 5,388 KB |
最終ジャッジ日時 | 2023-09-29 02:00:48 |
合計ジャッジ時間 | 4,202 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
5,156 KB |
testcase_01 | AC | 7 ms
5,316 KB |
testcase_02 | AC | 17 ms
5,180 KB |
testcase_03 | AC | 10 ms
5,160 KB |
testcase_04 | AC | 6 ms
5,108 KB |
testcase_05 | AC | 12 ms
5,100 KB |
testcase_06 | AC | 14 ms
5,108 KB |
testcase_07 | AC | 9 ms
5,172 KB |
testcase_08 | AC | 14 ms
5,232 KB |
testcase_09 | AC | 10 ms
5,100 KB |
testcase_10 | AC | 26 ms
5,244 KB |
testcase_11 | AC | 43 ms
5,096 KB |
testcase_12 | AC | 37 ms
5,252 KB |
testcase_13 | AC | 7 ms
5,108 KB |
testcase_14 | AC | 14 ms
5,240 KB |
testcase_15 | AC | 11 ms
5,096 KB |
testcase_16 | AC | 116 ms
5,152 KB |
testcase_17 | AC | 124 ms
5,240 KB |
testcase_18 | AC | 120 ms
5,284 KB |
testcase_19 | AC | 147 ms
5,176 KB |
testcase_20 | AC | 149 ms
5,236 KB |
testcase_21 | AC | 73 ms
5,176 KB |
testcase_22 | AC | 121 ms
5,388 KB |
testcase_23 | AC | 171 ms
5,244 KB |
testcase_24 | AC | 115 ms
5,236 KB |
testcase_25 | AC | 68 ms
5,376 KB |
testcase_26 | AC | 70 ms
5,104 KB |
testcase_27 | AC | 48 ms
5,240 KB |
testcase_28 | AC | 67 ms
5,196 KB |
testcase_29 | AC | 64 ms
5,180 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; int dp[2][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, 2) 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) dp[i + 1 & 1][j][k][l][m] = -inf; rep (j, 21) rep (k, 21) rep (l, 21) rep (m, 21) { chmax(dp[i + 1 & 1][j][k][l][m], dp[i & 1][j][k][l][m]); if (s[i] == 'K') { chmax(dp[i + 1 & 1][j + 1][k][l][m], dp[i & 1][j][k][l][m]); } else if (s[i] == 'U') { if (j) chmax(dp[i + 1 & 1][j - 1][k + 1][l][m], dp[i & 1][j][k][l][m]); } else if (s[i] == 'R') { if (k) chmax(dp[i + 1 & 1][j][k - 1][l + 1][m], dp[i & 1][j][k][l][m]); } else if (s[i] == 'O') { if (l) chmax(dp[i + 1 & 1][j][k][l - 1][m + 1], dp[i & 1][j][k][l][m]); } else if (s[i] == 'I') { if (m) chmax(dp[i + 1 & 1][j][k][l][m - 1], dp[i & 1][j][k][l][m] + 1); } else if (s[i] == '?') { chmax(dp[i + 1 & 1][j + 1][k][l][m], dp[i & 1][j][k][l][m]); if (j) chmax(dp[i + 1 & 1][j - 1][k + 1][l][m], dp[i & 1][j][k][l][m]); if (k) chmax(dp[i + 1 & 1][j][k - 1][l + 1][m], dp[i & 1][j][k][l][m]); if (l) chmax(dp[i + 1 & 1][j][k][l - 1][m + 1], dp[i & 1][j][k][l][m]); if (m) chmax(dp[i + 1 & 1][j][k][l][m - 1], dp[i & 1][j][k][l][m] + 1); } } } int ans = 0; rep (j, 21) rep (k, 21) rep (l, 21) rep (m, 21) { chmax(ans, dp[N & 1][j][k][l][m]); } cout << ans << endl; return 0; }