Submission #63031402
Source Code Expand
Copy
import syssys.setrecursionlimit(1000000000)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]])def getMinPalindromic(a,b,alreadyVisited = set([])):if a == b:return 0characters = set([])characterDict = {}
import sys
sys.setrecursionlimit(1000000000)
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]])
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 | 1717 Byte |
| Status | RE |
| Exec Time | 2280 ms |
| Memory | 1325272 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 | AC | 10 ms | 8836 KiB |
| sample01.txt | AC | 10 ms | 8884 KiB |
| testcase00.txt | AC | 10 ms | 8856 KiB |
| testcase01.txt | AC | 10 ms | 8856 KiB |
| testcase02.txt | TLE | 2210 ms | 42104 KiB |
| testcase03.txt | TLE | 2262 ms | 978488 KiB |
| testcase04.txt | RE | 10 ms | 8868 KiB |
| testcase05.txt | RE | 10 ms | 8788 KiB |
| testcase06.txt | RE | 10 ms | 8800 KiB |
| testcase07.txt | RE | 10 ms | 8816 KiB |
| testcase08.txt | AC | 71 ms | 9588 KiB |
| testcase09.txt | AC | 196 ms | 9952 KiB |
| testcase10.txt | AC | 52 ms | 9328 KiB |
| testcase11.txt | AC | 220 ms | 9940 KiB |
| testcase12.txt | AC | 77 ms | 9672 KiB |
| testcase13.txt | AC | 142 ms | 9944 KiB |
| testcase14.txt | AC | 27 ms | 9268 KiB |
| testcase15.txt | AC | 229 ms | 10032 KiB |
| testcase16.txt | RE | 10 ms | 8792 KiB |
| testcase17.txt | RE | 10 ms | 8784 KiB |
| testcase18.txt | RE | 10 ms | 8832 KiB |
| testcase19.txt | RE | 10 ms | 8776 KiB |
| testcase20.txt | RE | 10 ms | 8828 KiB |
| testcase21.txt | TLE | 2247 ms | 724004 KiB |
| testcase22.txt | TLE | 2227 ms | 341588 KiB |
| testcase23.txt | TLE | 2223 ms | 274816 KiB |
| testcase24.txt | TLE | 2213 ms | 87272 KiB |
| testcase25.txt | TLE | 2214 ms | 103988 KiB |
| testcase26.txt | RE | 13 ms | 10380 KiB |
| testcase27.txt | TLE | 2273 ms | 1220924 KiB |
| testcase28.txt | TLE | 2224 ms | 287180 KiB |
| testcase29.txt | TLE | 2249 ms | 757680 KiB |
| testcase30.txt | TLE | 2223 ms | 212608 KiB |
| testcase31.txt | TLE | 2232 ms | 431344 KiB |
| testcase32.txt | RE | 11 ms | 8776 KiB |
| testcase33.txt | TLE | 2276 ms | 1280000 KiB |
| testcase34.txt | TLE | 2218 ms | 170956 KiB |
| testcase35.txt | TLE | 2263 ms | 1032076 KiB |
| testcase36.txt | TLE | 2227 ms | 357260 KiB |
| testcase37.txt | TLE | 2252 ms | 811680 KiB |
| testcase38.txt | RE | 11 ms | 8820 KiB |
| testcase39.txt | TLE | 2276 ms | 1285392 KiB |
| testcase40.txt | TLE | 2280 ms | 1325272 KiB |
| testcase41.txt | TLE | 2276 ms | 1286684 KiB |
| testcase42.txt | TLE | 2225 ms | 315540 KiB |
| testcase43.txt | TLE | 2264 ms | 1048068 KiB |
| testcase44.txt | RE | 11 ms | 8836 KiB |
| testcase45.txt | AC | 742 ms | 9368 KiB |
| testcase46.txt | TLE | 2208 ms | 14224 KiB |
| testcase47.txt | TLE | 2232 ms | 443956 KiB |
| testcase48.txt | TLE | 2240 ms | 602296 KiB |
| testcase49.txt | TLE | 2271 ms | 1177368 KiB |
| testcase50.txt | TLE | 2232 ms | 397264 KiB |
| testcase51.txt | TLE | 2273 ms | 1192896 KiB |
| testcase52.txt | TLE | 2213 ms | 96540 KiB |
| testcase53.txt | TLE | 2270 ms | 1154680 KiB |
| testcase54.txt | TLE | 2261 ms | 985248 KiB |
| testcase55.txt | TLE | 2270 ms | 1156724 KiB |