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.
Really don't know, why this problem is listed under 'Number Theory'.
To me it is plain linear algebra (e.g. Gauss elimination), in the boolean Field aka , $\mathbb{Z}_2 , wtf ...
# Enter your code here. Read input from STDIN. Print output to STDOUTread_ints=lambda:list(map(int,input().split()))defsolve(rect,mat_len):l=len(rect)ret=[0foriinrange(l)]pos=0foriinrange(l):whileTrue:find=Falseforjinrange(i,l):ifrect[j][pos]==1:rect[i],rect[j]=rect[j],rect[i]find=Truebreakiffind:breakelse:pos+=1ifpos==l:breakifpos==l:breakforjinrange(i+1,l):ifrect[j][pos]:forkinrange(pos,l+1):rect[j][k]^=rect[i][k]pos+=1ifpos==l:breakrect.reverse()foriinrange(l):pos=-1forjinrange(l+1):ifrect[i][j]:pos=jbreakifpos==l:print('Impossible')returnifpos==-1:continueret[pos]=rect[i][l]forjinrange(i+1,l):ifrect[j][pos]:forkinrange(pos,l+1):rect[j][k]^=rect[i][k]print('Possible')print(sum(ret))k=0foriinrange(mat_len):forjinrange(mat_len):if(ret[k]):print(i,j)k+=1if__name__=="__main__":[r,d]=read_ints()mat=[]foriinrange(r):mat.append(read_ints())rect=[]k=0foriinrange(r):forjinrange(r):rect.append([])foriter_iinrange(r):foriter_jinrange(r):ifabs(i-iter_i)+abs(j-iter_j)<=d:rect[k].append(1)else:rect[k].append(0)ifmat[i][j]:rect[k].append(1)else:rect[k].append(0)k+=1solve(rect,r)
For testcase #3, my submission was marked as giving the wrong answer. I downloaded the input and output for that testcase, and it said the output should be "impossible", but I worked out my program's solution for that testcase by hand and it seems to work. Also, I have a friend who also worked on this problem and his solution was marked correct on that testcase, but his program verified that that testcase should output "possible", and that my solution works. What's happening?
No more comments
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Wonderful blogpost. Find out more about apk legends fr
great post, also check SSS Contribution
Really don't know, why this problem is listed under 'Number Theory'.
To me it is plain linear algebra (e.g. Gauss elimination), in the boolean Field aka , $\mathbb{Z}_2 , wtf ...
Python 3 solution
For testcase #3, my submission was marked as giving the wrong answer. I downloaded the input and output for that testcase, and it said the output should be "impossible", but I worked out my program's solution for that testcase by hand and it seems to work. Also, I have a friend who also worked on this problem and his solution was marked correct on that testcase, but his program verified that that testcase should output "possible", and that my solution works. What's happening?