Thank it works for the first Test case now I have TLE for the second.
I don't understand how it changes something ?

Le jeudi 23 avril 2020 20:34:34 UTC+2, vijender ahlawat a écrit :
>
> Hi Quentin
>
> try changing score to long
>
> int score = 0;
>
> long score = 0;
>
> On Thursday, 23 April 2020 21:21:39 UTC+5:30, Quentin wrote:
>>
>> Hello,
>> I try to solve the Square Dance but I got WA even if on my local it is 
>> working.
>> I tried the example use case and the following use case :
>>
>> 4 4 => 54
>> 1 2 1 1
>> 3 1 2 1
>> 1 4 1 2
>> 1 1 3 1
>> 3 1 => 14
>> 3
>> 1
>> 2
>> 3 3 => 9
>> 1 1 1
>> 1 1 1
>> 1 1 1
>>
>>
>> And for me this is all good.
>>
>>
>> Can you suggest use case that can give a wrong answer ?
>>
>>
>>
>> import java.util.ArrayList;
>> import java.util.List;
>> import java.util.Scanner;
>>
>> public class Solution {
>> static boolean hasEliminationOccured = false;
>> 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++) {
>> int score = 0;
>> int R = scann.nextInt(); // Row
>> int C = scann.nextInt();//Column
>> List<Dancer> dancers = new ArrayList<>();
>> Dancer[][] S = new Dancer[R][C];
>> for(int i = 0; i< R;i++) {
>> for(int j = 0;j<C;j++) {
>> Dancer d = new Dancer(i, j, scann.nextInt());
>> dancers.add(d);
>> S[i][j] = d;
>> if(j>0) {
>> d.westDancer = S[i][j-1];
>> S[i][j-1].eastDancer = d;
>> }
>> if(i>0) {//Not on the first line
>> d.northDancer = S[i-1][j];
>> S[i-1][j].southDancer = d;
>> }
>> } 
>> }
>> hasEliminationOccured = danceContinue(dancers);
>> do {//danceContinue(dancers)
>> score+= turnScore(dancers);
>> eliminateDancers(dancers);
>> updateDancers(dancers);
>> }while(hasEliminationOccured);
>> //score+= turnScore(dancers);
>>
>>
>> System.out.println(String.format("Case #%s: %s",usease+1,score));
>> }
>> }
>>
>> private static void updateDancers(List<Dancer> dancers) {
>> dancers.stream().forEach(Dancer::updateNeighbours);
>> }
>>
>> private static void eliminateDancers(List<Dancer> dancers) {
>> long count = dancers.stream().filter(Dancer::isNotElminitated).count();
>> dancers.stream().forEach(Dancer::eliminate);
>> if(count != dancers.stream().filter(Dancer::isNotElminitated).count()) {
>> hasEliminationOccured = true;
>> }
>> else {
>> hasEliminationOccured = false;
>> }
>> }
>>
>> private static int turnScore(List<Dancer> dancers) {
>> return 
>> dancers.stream().filter(Dancer::isNotElminitated).map(x->x.skill).reduce(0, 
>> Integer::sum);
>> }
>>
>> private static boolean danceContinue(List<Dancer> dancers) {
>> return dancers.stream().filter(Dancer::hasNeighbourds).count()>0 ? true : 
>> false;
>> }
>>
>>
>>
>>
>>
>>
>>
>>
>> }
>> class Dancer{
>> int skill;
>> int c;
>> int r;
>> Dancer northDancer =null;
>> Dancer eastDancer=null;
>> Dancer southDancer=null;
>> Dancer westDancer=null;
>> boolean isElminitated =false;
>> public boolean isNotElminitated() {
>> return !this.isElminitated;
>> }
>> public void updateNeighbours() {
>> //TODO : if too slow update neighborhoods in both sides
>> northDancer = northDancer==null ? null : getNextNorthNeighbourd();
>> eastDancer = eastDancer==null ? null : getNextEasthNeighbourd();
>> southDancer = southDancer==null ? null : getNextSouthNeighbourd();
>> westDancer = westDancer==null ? null : getNextWestNeighbourd();
>> }
>> private Dancer getNextNorthNeighbourd() {
>> if(this.northDancer==null) return null;
>> if(this.northDancer.isElminitated) {
>> return this.northDancer.getNextNorthNeighbourd();
>> }
>> else {
>> return this.northDancer;
>> }
>> }
>>
>> private Dancer getNextEasthNeighbourd() {
>> if(this.eastDancer==null) return null;
>> if(this.eastDancer.isElminitated) {
>> return this.eastDancer.getNextEasthNeighbourd();
>> }
>> else {
>> return this.eastDancer;
>> }
>> }
>> private Dancer getNextSouthNeighbourd() {
>> if(this.southDancer==null) return null;
>> if(this.southDancer.isElminitated) {
>> return this.southDancer.getNextSouthNeighbourd();
>> }
>> else {
>> return this.southDancer;
>> }
>> }
>> private Dancer getNextWestNeighbourd() {
>> if(this.westDancer==null) return null;
>> if(this.westDancer.isElminitated) {
>> return this.westDancer.getNextWestNeighbourd();
>> }
>> else {
>> return this.westDancer;
>> }
>> }
>> public void eliminate() {
>> float average =0;
>> int count = 0;
>> if(northDancer!=null) {
>> count++;
>> average += northDancer.skill;
>> }
>> if(eastDancer!=null){
>> count++;
>> average += eastDancer.skill;
>> }
>> if(southDancer!=null){
>> count++;
>> average += southDancer.skill;
>> }
>> if(westDancer!=null){
>> count++;
>> average += westDancer.skill;
>> }
>> average/=count;
>> if(this.skill < average) {
>> isElminitated = true;
>> }
>> }
>> public boolean hasNeighbourds() {
>> return northDancer == null && eastDancer == null && southDancer == null 
>> && westDancer==null ? false : true;
>> }
>> public int getNeighbourdsCount() {
>> int count = 0;
>> if(northDancer!=null)count++;
>> if(eastDancer!=null)count++;
>> if(southDancer!=null)count++;
>> if(westDancer!=null)count++;
>> return count;
>> }
>> public Dancer(int r, int c ,int skill) {
>> this.c = c;
>> this.r = r;
>> this.skill = skill;
>> }
>> }
>>
>> Thank you in advance.
>>
>> Regards
>>
>>

-- 
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/a774087e-3433-4b4e-8795-4ba022541f20%40googlegroups.com.

Reply via email to