Submission #63030664
Source Code Expand
Copy
N = int(input())graph = {}graphInv = {}for i in range(N):C = input()graph[i] = []for j in range(N):if C[j] != "-":graph[i].append([j, C[j]])if j not in graphInv:graphInv[j] = []graphInv[j].append([i, C[j]])print(graph,graphInv)def getMinPalindromic(a,b,alreadyVisited = set([])):if a == b:return 0characters = set([])characterDict = {}for i in graph[a]:characters.add(i[1])
N = int(input())
graph = {}
graphInv = {}
for i in range(N):
C = input()
graph[i] = []
for j in range(N):
if C[j] != "-":
graph[i].append([j, C[j]])
if j not in graphInv:
graphInv[j] = []
graphInv[j].append([i, C[j]])
print(graph,graphInv)
def getMinPalindromic(a,b,alreadyVisited = set([])):
if a == b:
return 0
characters = set([])
characterDict = {}
for i in graph[a]:
characters.add(i[1])
if i[1] not in characterDict:
characterDict[i[1]] = []
characterDict[i[1]].append(i[0])
characters2 = set([])
characterDict2 = {}
for i in graphInv[b]:
characters2.add(i[1])
if i[1] not in characterDict2:
characterDict2[i[1]] = []
characterDict2[i[1]].append(i[0])
characters = characters & characters2
if len(characters) == 0:
return -1
mini = 99999999999999
for i in characters:
for j in characterDict[i]:
if j == b:
return 1
for k in characterDict2[i]:
if k == a:
return 1
if not (j,k) in alreadyVisited:
copy = alreadyVisited.copy()
copy.add((j,k))
result = getMinPalindromic(j,k,copy)
if result != -1:
mini = min(mini, result + 2)
if mini == 99999999999999:
return -1
return mini
for i in range(N):
ans = []
for j in range(N):
ans.append(getMinPalindromic(i,j))
print(" ".join(map(str,ans)))
Submission Info
| Submission Time | |
|---|---|
| Task | E - Palindromic Shortest Path |
| User | kangping |
| Language | Python (CPython 3.11.4) |
| Score | 0 |
| Code Size | 1691 Byte |
| Status | RE |
| Exec Time | 2208 ms |
| Memory | 44080 KiB |
Judge Result
| Set Name | Sample | All | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 450 | ||||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample00.txt, sample01.txt |
| All | sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt, testcase52.txt, testcase53.txt, testcase54.txt, testcase55.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample00.txt | WA | 10 ms | 8776 KiB |
| sample01.txt | WA | 10 ms | 8744 KiB |
| testcase00.txt | WA | 10 ms | 8752 KiB |
| testcase01.txt | WA | 10 ms | 8760 KiB |
| testcase02.txt | RE | 73 ms | 38872 KiB |
| testcase03.txt | RE | 98 ms | 44080 KiB |
| testcase04.txt | RE | 10 ms | 8864 KiB |
| testcase05.txt | RE | 11 ms | 8860 KiB |
| testcase06.txt | RE | 11 ms | 8864 KiB |
| testcase07.txt | RE | 11 ms | 8808 KiB |
| testcase08.txt | WA | 94 ms | 9548 KiB |
| testcase09.txt | WA | 106 ms | 9568 KiB |
| testcase10.txt | WA | 36 ms | 9252 KiB |
| testcase11.txt | WA | 309 ms | 10052 KiB |
| testcase12.txt | WA | 90 ms | 9596 KiB |
| testcase13.txt | WA | 191 ms | 9900 KiB |
| testcase14.txt | WA | 27 ms | 8776 KiB |
| testcase15.txt | WA | 231 ms | 9988 KiB |
| testcase16.txt | RE | 10 ms | 8588 KiB |
| testcase17.txt | RE | 11 ms | 8796 KiB |
| testcase18.txt | RE | 11 ms | 8840 KiB |
| testcase19.txt | RE | 11 ms | 8796 KiB |
| testcase20.txt | RE | 11 ms | 8752 KiB |
| testcase21.txt | RE | 48 ms | 32044 KiB |
| testcase22.txt | RE | 63 ms | 32040 KiB |
| testcase23.txt | RE | 86 ms | 32364 KiB |
| testcase24.txt | RE | 179 ms | 32064 KiB |
| testcase25.txt | RE | 315 ms | 32644 KiB |
| testcase26.txt | RE | 13 ms | 10212 KiB |
| testcase27.txt | RE | 43 ms | 32180 KiB |
| testcase28.txt | RE | 46 ms | 32140 KiB |
| testcase29.txt | RE | 55 ms | 32568 KiB |
| testcase30.txt | RE | 53 ms | 32260 KiB |
| testcase31.txt | RE | 68 ms | 32860 KiB |
| testcase32.txt | RE | 11 ms | 8772 KiB |
| testcase33.txt | RE | 44 ms | 32312 KiB |
| testcase34.txt | RE | 45 ms | 32196 KiB |
| testcase35.txt | RE | 48 ms | 32712 KiB |
| testcase36.txt | RE | 47 ms | 32472 KiB |
| testcase37.txt | RE | 60 ms | 32888 KiB |
| testcase38.txt | RE | 12 ms | 8884 KiB |
| testcase39.txt | RE | 43 ms | 32340 KiB |
| testcase40.txt | RE | 49 ms | 32572 KiB |
| testcase41.txt | RE | 52 ms | 32744 KiB |
| testcase42.txt | RE | 47 ms | 32512 KiB |
| testcase43.txt | RE | 54 ms | 33080 KiB |
| testcase44.txt | RE | 11 ms | 8788 KiB |
| testcase45.txt | WA | 813 ms | 9256 KiB |
| testcase46.txt | TLE | 2208 ms | 13192 KiB |
| testcase47.txt | RE | 53 ms | 34088 KiB |
| testcase48.txt | RE | 53 ms | 34684 KiB |
| testcase49.txt | RE | 55 ms | 35328 KiB |
| testcase50.txt | RE | 54 ms | 35108 KiB |
| testcase51.txt | RE | 60 ms | 36076 KiB |
| testcase52.txt | RE | 53 ms | 34800 KiB |
| testcase53.txt | RE | 63 ms | 36744 KiB |
| testcase54.txt | RE | 63 ms | 36900 KiB |
| testcase55.txt | RE | 65 ms | 37412 KiB |