結果
問題 | No.2926 Botaoshi |
ユーザー | 学ぶマン |
提出日時 | 2024-10-12 16:14:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 262 ms / 2,000 ms |
コード長 | 2,789 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 142,144 KB |
最終ジャッジ日時 | 2024-10-12 16:14:58 |
合計ジャッジ時間 | 8,090 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,736 KB |
testcase_01 | AC | 43 ms
52,608 KB |
testcase_02 | AC | 40 ms
52,608 KB |
testcase_03 | AC | 40 ms
52,736 KB |
testcase_04 | AC | 41 ms
52,736 KB |
testcase_05 | AC | 41 ms
52,608 KB |
testcase_06 | AC | 42 ms
52,480 KB |
testcase_07 | AC | 41 ms
52,864 KB |
testcase_08 | AC | 42 ms
52,608 KB |
testcase_09 | AC | 42 ms
52,864 KB |
testcase_10 | AC | 43 ms
52,480 KB |
testcase_11 | AC | 42 ms
52,608 KB |
testcase_12 | AC | 225 ms
136,632 KB |
testcase_13 | AC | 221 ms
135,920 KB |
testcase_14 | AC | 257 ms
140,148 KB |
testcase_15 | AC | 43 ms
52,864 KB |
testcase_16 | AC | 176 ms
111,840 KB |
testcase_17 | AC | 206 ms
126,412 KB |
testcase_18 | AC | 105 ms
82,944 KB |
testcase_19 | AC | 166 ms
108,220 KB |
testcase_20 | AC | 126 ms
92,160 KB |
testcase_21 | AC | 152 ms
101,816 KB |
testcase_22 | AC | 188 ms
110,208 KB |
testcase_23 | AC | 91 ms
80,128 KB |
testcase_24 | AC | 177 ms
112,816 KB |
testcase_25 | AC | 102 ms
83,072 KB |
testcase_26 | AC | 203 ms
122,916 KB |
testcase_27 | AC | 154 ms
102,240 KB |
testcase_28 | AC | 98 ms
79,872 KB |
testcase_29 | AC | 96 ms
78,720 KB |
testcase_30 | AC | 125 ms
90,112 KB |
testcase_31 | AC | 114 ms
83,072 KB |
testcase_32 | AC | 129 ms
93,416 KB |
testcase_33 | AC | 191 ms
117,992 KB |
testcase_34 | AC | 172 ms
107,604 KB |
testcase_35 | AC | 83 ms
73,728 KB |
testcase_36 | AC | 252 ms
140,860 KB |
testcase_37 | AC | 253 ms
140,604 KB |
testcase_38 | AC | 262 ms
140,748 KB |
testcase_39 | AC | 245 ms
142,144 KB |
testcase_40 | AC | 253 ms
140,604 KB |
testcase_41 | AC | 203 ms
138,048 KB |
testcase_42 | AC | 205 ms
137,664 KB |
testcase_43 | AC | 187 ms
125,624 KB |
testcase_44 | AC | 181 ms
125,140 KB |
testcase_45 | AC | 178 ms
124,476 KB |
ソースコード
import sys, math sys.set_int_max_str_digits(0) inf = 1<<60 MOD = 998244353 class Modint(int): mod = 998244353 def modpow(self, i: int, r: int) -> int: return pow(i, r, Modint.mod) def modinv(self, i: int, r: int = 1) -> int: return pow(i, Modint.mod - 1 - r, Modint.mod) def __add__(self, other): return Modint(int.__add__(self, other) % Modint.mod) def __sub__(self, other): return Modint(int.__sub__(self, other) % Modint.mod) def __mul__(self, other): return Modint(int.__mul__(self, other) % Modint.mod) def __floordiv__(self, other): return Modint(int.__mul__(self, self.modinv(other)) % Modint.mod) __truediv__ = __floordiv__ def __pow__(self, other): return Modint(self.modpow(self, other)) def __radd__(self, other): return Modint(int.__add__(other, self) % Modint.mod) def __rsub__(self, other): return Modint(int.__sub__(other, self) % Modint.mod) def __rmul__(self, other): return Modint(int.__mul__(other, self) % Modint.mod) def __rfloordiv__(self, other): return Modint(int.__mul__(other, self.modinv(self)) % Modint.mod) __rtruediv__ = __rfloordiv__ def __rpow__(self, other): return Modint(self.modpow(other, self)) def __iadd__(self, other): self = self.__add__(other) return self def __isub__(self, other): self = self.__sub__(other) return self def __imul__(self, other): self = self.__mul__(other) return self def __ifloordiv__(self, other): self = self.__mul__(self.modinv(other)) return self def __neg__(self): return (self.mod - self) % self.mod __itruediv__ = __ifloordiv__ def __ipow__(self, other): self = Modint(self.modpow(self, other)) return self N = int(input()) S = ['U'] + list(input()) DP = [[Modint(0)] * (3) for _ in range(N + 1)] # j == 0 : | # j == 1 : \ # j == 2 : / # 初期状態で | が一本たっているとする DP[0][0] = 1 d = {} d['U'] = 0 d['L'] = 1 d['R'] = 2 for i in range(N): if S[i] != '.': srcj = d[S[i]] # DP[i][srcj] からの寄与のみ考える if srcj <= 1: for j in range(3): #dst DP[i + 1][j] += DP[i][srcj] else: for j in [0, 2]: DP[i + 1][j] += DP[i][srcj] else: # '.' だったら全部 for j in range(3): for dstj in range(3): # j == 2 and dstj == 1 のとき以外寄与つくる if j == 2 and dstj == 1: continue DP[i + 1][dstj] += DP[i][j] if S[-1] == '.': ans = sum(DP[-1]) else: ans = DP[-1][d[S[-1]]] print(ans%MOD)