Hi Manav,

U can post your question in the main forum as solo post in increase its 
reach. 

On Friday, 24 April 2020 02:19:55 UTC+5:30, MANAV KUMAR wrote:
>
> Hello Everyone, 
> I am Manav Kumar 3rd year undergrad.
> I am new to this group. I was just practicing previous years problem and 
> got stuck on one of them ( Round 1A 2018-  Edge Baking).
> I am facing a huge problem with it and have read it’s analysis and other’s 
> code too but barely go the hint to solve it.
> Can somebody please give some lead. It would be great help.
> Thanks in advance1
> Regards
> Manav
>
> On 23-Apr-2020, at 11:26 PM, vijender ahlawat <vick...@gmail.com 
> <javascript:>> wrote:
>
> 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 googl...@googlegroups.com <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/google-code/ffa0484b-4e91-47d6-baa9-fb7e1e8986bb%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/google-code/ffa0484b-4e91-47d6-baa9-fb7e1e8986bb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>

-- 
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/580a5f7a-f1c2-4f30-abbd-657bf733d6bd%40googlegroups.com.

Reply via email to