Submission #920585

# Submission time Handle Problem Language Result Execution time Memory
920585 2024-02-02T18:06:31 Z zeroday1934 Beads and wires (APIO14_beads) Python 3
0 / 100
11 ms 2908 KB
"""
ID: asp.5611
LANG: PYTHON3
TASK: beads
"""
def break_and_join(inp, idx):
    pp = inp[:idx]
    sp = inp[idx:]
    r = sp + pp
    return r
def count(string):
    c=0
    for j in range(len(string)):
        if(string[j]=='w'):
           c+=1
        else:
            ch=string[j]
            for i in range(j,len(string)):
                if(string[i]==ch or string[i]=='w'):
                    c+=1
                else:
                    break
            break
    for k in range(len(string)-1,-1,-1):
        
        if(string[k]=='w'):
           c+=1
           
        else:
            ch=string[k]
            for i in range(k,i>=0,-1):
                if(string[i]==ch or string[i]=='w'):
                    c+=1
                    
                else:
                    break
            break
    
    if(c>len(string)):
        c=len(string)
    return c
with open('beads.in','r') as f:
    N=int(f.readline())
    necklace=f.readline()
f.close()
counter=0
for i in range(N):
    res=break_and_join(necklace,i)
    c_count=count(res)
    
    if(c_count>counter):
        counter=c_count
with open('beads.out','w') as fout:
   fout.write(str(counter) + '\n')
fout.close()
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 2908 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -