結果
問題 | No.2926 Botaoshi |
ユーザー | 電たくT |
提出日時 | 2024-10-12 16:44:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 1,350 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 111,592 KB |
最終ジャッジ日時 | 2024-10-12 16:45:07 |
合計ジャッジ時間 | 4,332 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,480 KB |
testcase_01 | AC | 31 ms
52,608 KB |
testcase_02 | AC | 36 ms
52,608 KB |
testcase_03 | AC | 37 ms
52,224 KB |
testcase_04 | AC | 34 ms
52,224 KB |
testcase_05 | AC | 38 ms
51,968 KB |
testcase_06 | AC | 33 ms
52,096 KB |
testcase_07 | AC | 33 ms
52,352 KB |
testcase_08 | AC | 31 ms
52,352 KB |
testcase_09 | AC | 31 ms
52,480 KB |
testcase_10 | AC | 31 ms
52,352 KB |
testcase_11 | AC | 34 ms
52,352 KB |
testcase_12 | AC | 121 ms
109,184 KB |
testcase_13 | AC | 117 ms
108,800 KB |
testcase_14 | AC | 95 ms
108,672 KB |
testcase_15 | AC | 32 ms
52,224 KB |
testcase_16 | AC | 78 ms
90,772 KB |
testcase_17 | AC | 103 ms
108,032 KB |
testcase_18 | AC | 58 ms
73,600 KB |
testcase_19 | AC | 77 ms
87,808 KB |
testcase_20 | AC | 67 ms
81,380 KB |
testcase_21 | AC | 72 ms
85,376 KB |
testcase_22 | AC | 78 ms
87,620 KB |
testcase_23 | AC | 46 ms
66,176 KB |
testcase_24 | AC | 80 ms
89,340 KB |
testcase_25 | AC | 66 ms
72,704 KB |
testcase_26 | AC | 95 ms
104,912 KB |
testcase_27 | AC | 83 ms
85,632 KB |
testcase_28 | AC | 40 ms
65,024 KB |
testcase_29 | AC | 39 ms
63,232 KB |
testcase_30 | AC | 44 ms
72,192 KB |
testcase_31 | AC | 51 ms
71,552 KB |
testcase_32 | AC | 65 ms
82,984 KB |
testcase_33 | AC | 80 ms
90,808 KB |
testcase_34 | AC | 87 ms
88,960 KB |
testcase_35 | AC | 51 ms
64,896 KB |
testcase_36 | AC | 100 ms
108,928 KB |
testcase_37 | AC | 100 ms
108,260 KB |
testcase_38 | AC | 100 ms
108,136 KB |
testcase_39 | AC | 97 ms
109,040 KB |
testcase_40 | AC | 96 ms
108,948 KB |
testcase_41 | AC | 123 ms
111,592 KB |
testcase_42 | AC | 80 ms
94,000 KB |
testcase_43 | AC | 100 ms
111,532 KB |
testcase_44 | AC | 80 ms
93,824 KB |
testcase_45 | AC | 78 ms
93,952 KB |
ソースコード
N = int(input()) S = input() dp = [[0,0,0] for _ in range(N)] mod = 998244353 if S[0] == "L": dp[0][0] = 1 elif S[0] == "U": dp[0][1] = 1 elif S[0] == "R": dp[0][2] = 1 else: if len(S) == 1: dp[0][0] = 3 else: if S[1] == "L": dp[0][0],dp[0][1] = 1,1 else: dp[0] = [1,1,1] for a in range(1,N-1): X = [0,0,0] P = dp[a-1] if S[a] == ".": if S[a+1] == "L": X[0] = P[0] + P[1] X[1] = P[0] + P[1] + P[2] else: X[0] = P[0] + P[1] X[1] = P[1] + P[2] + P[0] X[2] = P[1] + P[2] + P[0] for b in range(3): X[b] %= mod elif S[a] == "L": X[0] = P[1] + P[0] X[0] %= mod elif S[a] == "U": X[1] = P[1] + P[2] + P[0] X[1] %= mod elif S[a] == "R": if S[a+1] == "L": pass else: X[2] = P[1] + P[2] + P[0] X[2] %= mod dp[a] = X if len(S) >= 2: X = [0,0,0] P = dp[N-2] if S[N-1] == ".": X[0] = P[1] + P[0] X[1] = P[1] + P[2] + P[0] X[2] = P[1] + P[2] + P[0] elif S[N-1] == "L": X[0] = P[1] + P[0] else: X[1] = P[1] + P[2] + P[0] for b in range(3): X[b] %= mod dp[N-1] = X print(sum(dp[N-1])%mod)