Submission #45437644


Source Code Expand

from itertools import permutations
M=int(input())
S=[]
for _ in range(3):
  s=input()
  S.append(s+s)

def solve(p,d):
  if any(d not in S[i] for i in range(3)): return 10**9
  crr=0
  for i in range(3):
    crr+=S[p[i]][crr%M:].index(d)+1
  return crr-1

ans=10**9
for d in range(10):
  for p in permutations(range(3)):
    ans=min(ans,solve(p,str(d)))

print(ans if ans!=10**9 else -1)

Submission Info

Submission Time
Task C - Slot Strategy 2 (Easy)
User kyopro_friends
Language Python (CPython 3.11.4)
Score 300
Code Size 406 Byte
Status AC
Exec Time 10 ms
Memory 9024 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 26
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 10 ms 8944 KiB
random_02.txt AC 10 ms 8876 KiB
random_03.txt AC 10 ms 8896 KiB
random_04.txt AC 10 ms 9024 KiB
random_05.txt AC 10 ms 8960 KiB
random_06.txt AC 10 ms 8884 KiB
random_07.txt AC 9 ms 8924 KiB
random_08.txt AC 10 ms 8896 KiB
random_09.txt AC 10 ms 8900 KiB
random_10.txt AC 10 ms 8896 KiB
random_11.txt AC 10 ms 8888 KiB
random_12.txt AC 10 ms 8968 KiB
random_13.txt AC 9 ms 8944 KiB
random_14.txt AC 10 ms 8968 KiB
random_15.txt AC 10 ms 8964 KiB
random_16.txt AC 10 ms 8968 KiB
random_17.txt AC 10 ms 8980 KiB
random_18.txt AC 10 ms 8996 KiB
random_19.txt AC 10 ms 8892 KiB
random_20.txt AC 10 ms 8876 KiB
random_21.txt AC 10 ms 8964 KiB
random_22.txt AC 10 ms 8980 KiB
random_23.txt AC 10 ms 8960 KiB
sample_01.txt AC 10 ms 8976 KiB
sample_02.txt AC 10 ms 8972 KiB
sample_03.txt AC 10 ms 8912 KiB