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.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;importjava.util.function.*;importjava.util.stream.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);intq=in.nextInt();for(inta0=0;a0<q;a0++){intn=in.nextInt();int[][]M=newint[n][n];for(intM_i=0;M_i<n;M_i++){for(intM_j=0;M_j<n;M_j++){M[M_i][M_j]=in.nextInt();}}intk=0;intcount1=0;intcount=0;List<Integer>l1=null;List<Integer>l2=null;// your code goes herefor(inti=0;i<n-1;i++){if(k<(n-1))for(intj=0;j<n;j++){l1=newArrayList<Integer>(M[k][j]);l2=newArrayList<Integer>(M[k+1][j]);}intsum1=l1.stream().mapToInt(Integer::intValue).sum();intsum2=l2.stream().mapToInt(Integer::intValue).sum();if((sum1==sum2)){count++;}k++;}k=0;for(inti=0;i<n-1;i++){if(k<(n-1))for(intj=0;j<n;j++){l1=newArrayList<Integer>(M[j][k]);l2=newArrayList<Integer>(M[j][k+1]);}ints1=l1.stream().mapToInt(Integer::intValue).sum();ints2=l2.stream().mapToInt(Integer::intValue).sum();if((s1==s2)){count1++;}else{count1--;}k++;}if(count==count1){System.out.println("Possible");}else{System.out.println("Impossible");}}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Organizing Containers of Balls
You are viewing a single comment's thread. Return to all comments →
help please