Rezultati

Up. imeNalogaJezikRezultatČas oddaje
muzik-2017 Prijateljske besede Python 3 100/100OK 20. apr '17 @ 17:20

Test Točke Porabljen spomin Porabljen čas Status
#1 12/12 9,039 MiB 0,000 s OK
#2 12/12 9,059 MiB 0,000 s OK
#3 12/12 9,262 MiB 1,185 s OK
#4 12/12 9,238 MiB 2,089 s OK
#5 13/13 9,215 MiB 0,000 s OK
#6 13/13 9,238 MiB 0,977 s OK
#7 13/13 9,223 MiB 0,000 s OK
#8 13/13 9,227 MiB 1,541 s OK

Ocenjevani program (besede.py):
import sys
from collections import deque

sys.setrecursionlimit(10**9*2)

#sys.stdin = open("besede.in")

sin = sys.stdin

n = int(sin.readline().strip())

priq = deque()
predq = deque()

beseda = sin.readline().strip()
predq.append(beseda[:3])
priq.append(beseda[-3:])

sez = []
for i in sin:
    sez.append(i.strip())
count = 1
while(1):
    a = []
    if len(predq) > 0:
        pred = predq.pop()
        for i in sez:
            if i[:3] == pred:
                #print (i)
                count += 1
                priq.append(i[-3:])
            else:
                a.append(i)
        sez = a
    a = []
    if len(priq) > 0:
        pri = priq.pop()
        for i in sez:
            if i[-3:] == pri:
                #print("::" + i)
                count += 1
                predq.append(i[:3])
            else:
                a.append(i)
        sez = a
    if len(priq) == 0 and len(predq) == 0:
        break
print (count)