Would you mind explaining your solution?

On Wednesday, August 19, 2020 at 7:15:53 AM UTC-7 Quentin wrote:

> Hello all,
>
> I am trying to solve the Stable Wall problem but I got a WA even for the 
> first use case but I don't know why ?
> I tried multiple use case and all is ok on my side but not ok on the 
> Judgment engine.
>
> Here is my code :
>
>
>
>
> import java.util.ArrayList;
> import java.util.Arrays;
> import java.util.Collections;
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.LinkedHashSet;
> import java.util.LinkedList;
> import java.util.List;
> import java.util.Scanner;
> import java.util.Set;
> import java.util.stream.Collectors;
>
>
> public class Solution {
>
>
>
>
>  static Solution sol = new Solution();
>   
>   
>  public static void main(String[] args) {
>  Scanner scann = new Scanner(System.in);  // Create a Scanner object
>  int T = scann.nextInt();
>
>
>  for(int usease = 0; usease< T;usease++) {
>  boolean hasSolution = false;
>  int R = scann.nextInt();
>  int C = scann.nextInt();
>  LinkedHashSet<String> solution = new LinkedHashSet<>();
>  Set<String> allPolyominos = new HashSet<>();
>  
>  List<List<String>> table = new ArrayList<>();
>  
>  for(int i = 0;i < R ;i++) {
>  List<String> currentLine = Arrays.asList(scann.next().split(""));
>  table.add(currentLine);
>  allPolyominos.addAll(currentLine.stream().collect(Collectors.toSet()));
>  if(i>0) {//If not the first line
>  List<String> previousLine = table.get(i-1);
>  for(int j = 0 ; j < C ; j++) {
>  if(!currentLine.get(j).contentEquals(previousLine.get(j))) {//Check each 
> cell of the current line with the previous from top to bottom and if 
> different add the previous line Polyominos
>  solution.add(previousLine.get(j));
>  }
>  }
>  }
>  }
>  
>  if(allPolyominos.size()!=solution.size()) {//There is a solution if all 
> Polyominos are not in the solution list, meaning a Polyominos reach the 
> bottom of the Wall
>  allPolyominos.removeAll(solution);
>  solution.addAll(allPolyominos);
>  hasSolution= true;
>  }
>
>
>  //Format the answer
>  Iterator<String> iterator = solution.iterator();
>  StringBuilder sb = new StringBuilder();
>  while(iterator.hasNext()) {
>  sb.append(iterator.next());
>  }
>  
>  
>  
>  if(hasSolution)
>  System.out.println(String.format("Case #%s: %s",usease+1,sb.reverse().
> toString()));
>  else
>  System.out.println(String.format("Case #%s: -1",usease+1));
>
>
>  }
>
>
>
>
>  }
>  
>
>
> }
>
>
> If you see any mistakes, thx.
> Regards
>
> Quentin
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-code+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/bbe3ef6b-4e62-466a-bc72-b8f90bd5cfb2n%40googlegroups.com.

Reply via email to