結果
問題 |
No.291 黒い文字列
|
ユーザー |
![]() |
提出日時 | 2015-10-20 00:35:20 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,412 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 264,224 KB |
最終ジャッジ日時 | 2024-07-22 10:24:29 |
合計ジャッジ時間 | 7,089 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 RE * 1 |
other | AC * 7 WA * 2 RE * 8 TLE * 1 -- * 8 |
ソースコード
from itertools import product def solve(): SS = input() S = [c for c in SS if c in 'KUROI?'] L1 = len(S) L2 = L1 // 5 + 1 dp = [[[[[-1 for o in range(L2)] for r in range(L2)] for u in range(L2)] for k in range(L2)] for x in range(L1 + 1)] # dp[x][k][u][r][o] = 次に見るのが x 文字目で、 kまで: k個、uまで: u個、rまで: r個、oまで: o個 のとき、i までできた数 dp[0][0][0][0][0] = 0 ma = 0 for x, c in enumerate(S): dpx = dp[x] for k, u, r, o in product(range(L2), repeat=4): if dpx[k][u][r][o] < 0: continue now = dpx[k][u][r][o] dpy = dp[x + 1] if (c == 'K' or c == '?') and k < 20: dpy[k + 1][u][r][o] = max(dpy[k + 1][u][r][o], now) if (c == 'U' or c == '?') and u < 20 and k: dpy[k - 1][u + 1][r][o] = max(dpy[k - 1][u + 1][r][o], now) if (c == 'R' or c == '?') and r < 20 and u: dpy[k][u - 1][r + 1][o] = max(dpy[k][u - 1][r + 1][o], now) if (c == 'O' or c == '?') and o < 20 and r: dpy[k][u][r - 1][o + 1] = max(dpy[k][u][r - 1][o + 1], now) if (c == 'I' or c == '?') and o: dpy[k][u][r][o - 1] = max(dpy[k][u][r][o - 1], now + 1) ma = max(ma, now + 1) print(ma) if __name__ == '__main__': solve()