Submission #1176991
Source Code Expand
import random import copy def gcd(a, b): while b: a, b = b, a % b return a def gcdm(x): g=x[0] for i in range(1,len(x)): g=gcd(g,x[i]) return(g) def candi(x): d=dict() for i in range(len(x)): d[x[i]]=i y=list(d.values()) return(y) def sto(N,AAA,tryno,isFirst=True): AA=copy.deepcopy(AAA) ply=0 moves=[] moves_win=[] if max(AA)<=1: return(0,0,True) cAA=candi(AA) for j in cAA: if AA[j]>1: win=0 for r in range(tryno): A=copy.deepcopy(AA) ply=1 A[j]-=1 g=gcdm(A) A=[x//g for x in A] while max(A)>1 and min(A)>1: ca=candi(A) i=ca[random.randint(0,len(ca)-1)] if A[i]>1: ply+=1 A[i]-=1 g=gcdm(A) A=[x//g for x in A] ply+=sum(A)-N if (ply %2==0)!=isFirst:win+=1 moves.extend([j]) moves_win.extend([win]) if isFirst: player='First' ans=max(moves_win) else: player='Second' ans=min(moves_win) selected=moves[moves_win.index(ans)] #print(AAA) #print(cAA) #print(moves_win,player,selected) AAA[selected]-=1 g=gcdm(AAA) AAA=[x//g for x in AAA] #print(AAA) return([selected,ans,False,AAA]) N=int(input()) AAA=[int(x) for x in input().split()] tryno=100 F=[] isFirst=True while max(AAA)>1 and min(AAA)>1: y=sto(N,AAA,tryno,isFirst) if y[2]: break F.extend([y[0]]) isFirst=(isFirst!=True) AAA=y[3] judge=len(F)+sum(AAA)-N if judge%2==1: print('First') else: print('Second')
Submission Info
Submission Time | |
---|---|
Task | D - Decrementing |
User | Pgmto70 |
Language | Python (3.4.3) |
Score | 0 |
Code Size | 1511 Byte |
Status | TLE |
Exec Time | 2106 ms |
Memory | 38480 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1000 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | TLE | 2106 ms | 36352 KB |
in10.txt | TLE | 2106 ms | 36616 KB |
in11.txt | TLE | 2106 ms | 36512 KB |
in12.txt | TLE | 2106 ms | 36612 KB |
in13.txt | TLE | 2105 ms | 38480 KB |
in14.txt | TLE | 2105 ms | 17680 KB |
in15.txt | TLE | 2106 ms | 36352 KB |
in16.txt | TLE | 2105 ms | 17936 KB |
in17.txt | TLE | 2106 ms | 36512 KB |
in18.txt | TLE | 2105 ms | 16788 KB |
in19.txt | TLE | 2105 ms | 34968 KB |
in2.txt | TLE | 2106 ms | 36352 KB |
in20.txt | TLE | 2105 ms | 17312 KB |
in21.txt | TLE | 2105 ms | 17120 KB |
in22.txt | TLE | 2105 ms | 17112 KB |
in23.txt | TLE | 2105 ms | 17116 KB |
in24.txt | TLE | 2105 ms | 17116 KB |
in25.txt | TLE | 2104 ms | 19744 KB |
in26.txt | TLE | 2105 ms | 17116 KB |
in27.txt | TLE | 2105 ms | 16900 KB |
in28.txt | TLE | 2105 ms | 17112 KB |
in29.txt | TLE | 2105 ms | 17564 KB |
in3.txt | TLE | 2106 ms | 36356 KB |
in30.txt | TLE | 2105 ms | 17116 KB |
in31.txt | TLE | 2106 ms | 36356 KB |
in32.txt | TLE | 2106 ms | 36616 KB |
in33.txt | TLE | 2105 ms | 16804 KB |
in34.txt | TLE | 2105 ms | 17116 KB |
in35.txt | TLE | 2105 ms | 17404 KB |
in36.txt | AC | 25 ms | 3828 KB |
in37.txt | AC | 25 ms | 3828 KB |
in4.txt | TLE | 2106 ms | 36352 KB |
in5.txt | TLE | 2106 ms | 36684 KB |
in6.txt | TLE | 2106 ms | 36356 KB |
in7.txt | TLE | 2106 ms | 36612 KB |
in8.txt | TLE | 2106 ms | 37508 KB |
in9.txt | TLE | 2106 ms | 36608 KB |
sample1.txt | AC | 32 ms | 3824 KB |
sample2.txt | AC | 26 ms | 3828 KB |
sample3.txt | AC | 42 ms | 3828 KB |