/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error Traceback (most recent call last): File "foo.py", line 46, in <module> File "foo.py", line 36, in solve IndexError: list index out of range 52ms 27.84 MiB
#2 Runtime Error Traceback (most recent call last): File "foo.py", line 46, in <module> File "foo.py", line 36, in solve IndexError: list index out of range 51ms 27.871 MiB

Code

from itertools import permutations

MOD = 1000000007
M = 2 * 10**5 + 10

cost = [[0] * 26 for _ in range(26)]
all_permutations = []

def precal():
    vowel = "aeiou"
    for i in range(len(vowel)):
        l = i
        cnt = 0
        while cnt < 5:
            cost[ord(vowel[i]) - ord('a')][ord(vowel[l]) - ord('a')] = cnt
            l += 1
            cnt += 1
            if l == 5:
                l = 0
    all_permutations.append(vowel)
    for perm in permutations(vowel):
        all_permutations.append("".join(perm))

def solve():
    t = 1
    precal()
    for _ in range(t):
        n = int(input())
        s = input()
        mx = MOD
        for perm in all_permutations:
            p = perm
            dp = [[0] * 5 for _ in range(n + 1)]
            for i in range(5):
                for j in range(1, n + 1):
                    pro = cost[ord(s[j - 1]) - ord('a')][ord(p[i]) - ord('a')]
                    if i == 0:
                        dp[j][i] = dp[j - 1][i] + pro
                    else:
                        dp[j][i] = dp[j - 1][i] + pro
                        dp[j][i] = min(dp[j][i], dp[j][i - 1])
                mx = min(mx, dp[n][i])
        print(mx)

if __name__ == "__main__":
    solve()

Information

Submit By
Type
Submission
Problem
P1140 Vowel arrangement
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2024-11-27 14:14:51
Judged At
2024-11-27 14:14:51
Judged By
Score
0
Total Time
52ms
Peak Memory
27.871 MiB