結果
問題 | No.762 PDCAパス |
ユーザー | mkawa2 |
提出日時 | 2021-03-04 23:22:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 356 ms / 2,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 201 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 28,544 KB |
最終ジャッジ日時 | 2024-10-05 13:13:55 |
合計ジャッジ時間 | 8,262 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 31 ms
10,880 KB |
testcase_02 | AC | 31 ms
10,752 KB |
testcase_03 | AC | 30 ms
10,880 KB |
testcase_04 | AC | 30 ms
11,008 KB |
testcase_05 | AC | 31 ms
10,752 KB |
testcase_06 | AC | 30 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 30 ms
10,880 KB |
testcase_09 | AC | 31 ms
10,880 KB |
testcase_10 | AC | 30 ms
10,752 KB |
testcase_11 | AC | 30 ms
10,752 KB |
testcase_12 | AC | 31 ms
10,880 KB |
testcase_13 | AC | 31 ms
10,752 KB |
testcase_14 | AC | 30 ms
11,008 KB |
testcase_15 | AC | 31 ms
10,752 KB |
testcase_16 | AC | 30 ms
10,880 KB |
testcase_17 | AC | 30 ms
10,752 KB |
testcase_18 | AC | 30 ms
10,752 KB |
testcase_19 | AC | 31 ms
10,880 KB |
testcase_20 | AC | 31 ms
10,752 KB |
testcase_21 | AC | 30 ms
10,752 KB |
testcase_22 | AC | 193 ms
11,776 KB |
testcase_23 | AC | 192 ms
11,648 KB |
testcase_24 | AC | 356 ms
28,544 KB |
testcase_25 | AC | 350 ms
28,544 KB |
testcase_26 | AC | 216 ms
13,696 KB |
testcase_27 | AC | 214 ms
13,696 KB |
testcase_28 | AC | 354 ms
26,112 KB |
testcase_29 | AC | 356 ms
26,112 KB |
testcase_30 | AC | 311 ms
22,400 KB |
testcase_31 | AC | 314 ms
22,400 KB |
testcase_32 | AC | 318 ms
22,400 KB |
testcase_33 | AC | 278 ms
19,328 KB |
testcase_34 | AC | 279 ms
19,328 KB |
testcase_35 | AC | 287 ms
19,456 KB |
testcase_36 | AC | 235 ms
14,464 KB |
testcase_37 | AC | 234 ms
14,336 KB |
testcase_38 | AC | 240 ms
14,464 KB |
testcase_39 | AC | 238 ms
14,336 KB |
testcase_40 | AC | 228 ms
14,208 KB |
ソースコード
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.buffer.readline()) def FI(): return float(sys.stdin.buffer.readline()) def MI(): return map(int, sys.stdin.buffer.readline().split()) def MF(): return map(float, sys.stdin.buffer.readline().split()) def MI1(): return map(int1, sys.stdin.buffer.readline().split()) def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def LI1(): return list(map(int1, sys.stdin.buffer.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] inf = 10**16 # md = 998244353 md = 10**9+7 t = "PDCA" n, m = MI() s = SI() order = [t.index(c) for c in s] to = [[] for _ in range(n)] for _ in range(m): u, v = MI1() if order[u]+1 == order[v]: to[u].append(v) if order[u] == order[v]+1: to[v].append(u) ctou = [[] for _ in range(4)] for u in range(n): ctou[order[u]].append(u) dp = [0]*n for u in ctou[0]: dp[u] = 1 for uu in ctou[:3]: for u in uu: dp[u] %= md for v in to[u]: dp[v] += dp[u] ans = 0 for u in ctou[3]: ans += dp[u] ans %= md print(ans)