답안 #197970

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197970 2020-01-24T12:25:33 Z model_code Preokret (COCI19_preokret) Python 3
50 / 50
39 ms 3428 KB
def prebroji_1(i,dx):
    duljina = 0
    while i > 0 and i + dx < N and (razlika[i] - razlika[i+dx] == dx):
        duljina += 1
        i += dx
    return duljina

def prebroji_2(i,dx):
    duljina = 0
    while i > 0 and i + dx < N and (razlika[i] - razlika[i+dx] == -dx):
        duljina += 1
        i += dx
    return duljina

N = int(input())

city = protivnik = 0
razlika = [0] * N
nule = []

for i in range(N):
    gol = int(input())

    if gol == 1:
        city += 1
    else:
        protivnik += 1

    razlika[i] = city - protivnik

    if razlika[i] == 0:
        nule += [i]

print(city, protivnik)
print(razlika.count(0) + 1)

preokret = 0
for i in nule:
    lijevo = prebroji_1(i,-1)
    desno = prebroji_1(i,1)
    if lijevo != 0 and desno != 0 and lijevo + desno > preokret:
        preokret = lijevo + desno
    lijevo = prebroji_2(i,-1)
    desno = prebroji_2(i,1)
    if lijevo != 0 and desno != 0 and lijevo + desno > preokret:
        preokret = lijevo + desno

print(preokret)
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3324 KB Output is correct
2 Correct 26 ms 3328 KB Output is correct
3 Correct 25 ms 3428 KB Output is correct
4 Correct 25 ms 3428 KB Output is correct
5 Correct 25 ms 3428 KB Output is correct
6 Correct 26 ms 3332 KB Output is correct
7 Correct 26 ms 3428 KB Output is correct
8 Correct 25 ms 3336 KB Output is correct
9 Correct 26 ms 3428 KB Output is correct
10 Correct 39 ms 3428 KB Output is correct