結果
問題 | No.1612 I hate Construct a Palindrome |
ユーザー | mkawa2 |
提出日時 | 2024-06-13 23:53:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 802 ms / 2,000 ms |
コード長 | 1,692 bytes |
コンパイル時間 | 648 ms |
コンパイル使用メモリ | 82,524 KB |
実行使用メモリ | 164,492 KB |
最終ジャッジ日時 | 2024-06-13 23:53:42 |
合計ジャッジ時間 | 12,487 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
55,160 KB |
testcase_01 | AC | 89 ms
74,588 KB |
testcase_02 | AC | 513 ms
164,344 KB |
testcase_03 | AC | 42 ms
55,068 KB |
testcase_04 | AC | 77 ms
74,060 KB |
testcase_05 | AC | 471 ms
164,492 KB |
testcase_06 | AC | 560 ms
148,160 KB |
testcase_07 | AC | 549 ms
148,536 KB |
testcase_08 | AC | 508 ms
141,604 KB |
testcase_09 | AC | 421 ms
132,700 KB |
testcase_10 | AC | 470 ms
131,636 KB |
testcase_11 | AC | 452 ms
131,848 KB |
testcase_12 | AC | 522 ms
137,240 KB |
testcase_13 | AC | 491 ms
137,340 KB |
testcase_14 | AC | 491 ms
137,444 KB |
testcase_15 | AC | 666 ms
147,036 KB |
testcase_16 | AC | 802 ms
154,468 KB |
testcase_17 | AC | 754 ms
154,852 KB |
testcase_18 | AC | 57 ms
66,400 KB |
testcase_19 | AC | 67 ms
67,960 KB |
testcase_20 | AC | 59 ms
66,460 KB |
testcase_21 | AC | 65 ms
70,624 KB |
testcase_22 | AC | 64 ms
69,136 KB |
testcase_23 | AC | 66 ms
70,460 KB |
testcase_24 | AC | 66 ms
70,308 KB |
testcase_25 | AC | 63 ms
69,392 KB |
testcase_26 | AC | 65 ms
70,440 KB |
testcase_27 | AC | 43 ms
55,692 KB |
testcase_28 | AC | 43 ms
54,928 KB |
testcase_29 | AC | 43 ms
54,496 KB |
testcase_30 | AC | 43 ms
54,992 KB |
testcase_31 | AC | 43 ms
54,664 KB |
testcase_32 | AC | 42 ms
54,780 KB |
testcase_33 | AC | 43 ms
54,004 KB |
testcase_34 | AC | 49 ms
54,796 KB |
testcase_35 | AC | 43 ms
55,596 KB |
testcase_36 | AC | 44 ms
53,988 KB |
testcase_37 | AC | 43 ms
54,352 KB |
testcase_38 | AC | 42 ms
55,100 KB |
ソースコード
import sys # sys.setrecursionlimit(1000006) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) # md = 10**9+7 md = 998244353 from collections import deque n, m = LI() to = [[] for _ in range(n)] cc = [] uv = [] for i in range(m): u, v, c = SI().split() u = int1(u) v = int1(v) c = ord(c)-97 to[u].append((v, i)) to[v].append((u, i)) cc.append(c) uv.append(u ^ v) q = deque() # dp = [[0]*27 for _ in range(n)] ee = [[None]*27 for _ in range(n)] for v, i in to[0]: c = cc[i] # dp[v][c] = 1 ee[v][c] = (0, -1, i) q.append((v, c)) while q: u, c = q.popleft() for v, i in to[u]: nc = c if c != cc[i]: nc = 26 if ee[v][nc]: continue # dp[v][nc] = 1 ee[v][nc] = (u,c,i) q.append((v, nc)) # p2D(ee) if ee[-1][-1] == None: print(-1) exit() ii = [] u = n-1 c = 26 while c!=-1: u,c,i = ee[u][c] ii.append(i) s=[cc[i] for i in ii] if s==s[::-1]: ii.append(ii[-1]) ii.append(ii[-1]) print(len(ii)) for i in ii[::-1]:print(i+1)