We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
MAXN=53G=[-1]*MAXNdp=[[-1for_inrange(15)]for_inrange(MAXN)]vis=[[Falsefor_inrange(100000)]for_inrange(MAXN)]defgrundy(pile_size):ifG[pile_size]!=-1:returnG[pile_size]backTrack(pile_size,pile_size)ret=0whilevis[pile_size][ret]:ret+=1G[pile_size]=retreturnretdefgetCount(s,k):ifk==0:returnint(s==0)ifdp[s][k]!=-1:returndp[s][k]ret=0foriinrange(1,s// k + 1):ret+=getCount(s-k*i,k-1)dp[s][k]=retreturnretdefbackTrack(init_pile_size,curr_pile_size,prev=0,xr=0):ifcurr_pile_size==0:ifprev:vis[init_pile_size][xr]=Truereturnst=prev+1foriinrange(st,min(curr_pile_size,init_pile_size-1)+1):backTrack(init_pile_size,curr_pile_size-i,i,xr^grundy(i))defmain():importsysinput=sys.stdin.readdata=input().split()t=int(data[0])index=1for_inrange(t):n=int(data[index])index+=1xr=0for_inrange(1,n+1):v=int(data[index])index+=1xr^=grundy(v)ifxr:print("ALICE")else:print("BOB")if__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stone Piles
You are viewing a single comment's thread. Return to all comments →