为什么我在这两个代码的Codeforces平台上出现运行时错误?

时间:2019-11-22 14:52:55

标签: python python-3.7

这是我的提交链接: -对于以下问题:https://www.dfn-cert.de/informationen/themen/verschluesselung_und_pki/openssl-kurzreferenz.html https://codeforces.com/problemset/problem/1257/C

test=int(input())
for testing in range(test):
    n=int(input())
    t=[int(x) for x in input().split()]
    if n<=1:
        print(-1)
    else :
        l=[x for x in t if t.count(x)>1]
        l=[x for x in set(l)]
        pointer=[]
        for x in l:
            joker=True
            i=0
            while i<len(t):
                if t[i]==x and joker:
                    s=i
                    joker=False
                if t[i]==x and not joker and i!=s:
                    pointer.append(t[s:i+1])
                    joker=True
                    i-=1
                i+=1
        print(min(map(len,pointer)))

预先感谢^^,我仍然不知道运行时错误来自

1 个答案:

答案 0 :(得分:-1)

我发现了它的主要原因,这主要是尝试或期望您需要避免排他如排空然后在其他事情之后调用它这样的排他性行为。我只是固定了代码:

test=int(input())
for testing in range(test):
    n=int(input())
    t=[int(x) for x in input().split()]
    if n<=1 :
        print(-1)
        continue
    else :
        pointer=[[False,0] for i in range(max(max(t),len(t))+1)]
        first=True
        mini=-1
        for i in range(len(t)):
            if not pointer[t[i]][0]:
                pointer[t[i]][1]=i
                pointer[t[i]][0]=True
                continue
            if pointer[t[i]][0]:
                if first :
                    mini=i-pointer[t[i]][1]+1
                    first=False
                else:
                    a=i-pointer[t[i]][1]+1
                    if mini>a:
                        mini=a
            pointer[t[i]][1]=i
            pointer[t[i]][0]=True
            if mini==2:
                break
    print(mini)