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.util.Scanner;importjava.util.HashMap;publicclassGridlandMetro{staticlonggridlandMetro(intn,intm,intk,int[][]track){longtotal=(long)n*m;HashMap<Integer,int[]>d=newHashMap<>();for(inti=0;i<k;i++){intr=track[i][0];intc1=track[i][1];intc2=track[i][2];if(!d.containsKey(r)){d.put(r,newint[]{c1,c2});>>}elseif(c1>d.get(r)[1]){total-=c2-c1+1;}elseif(c2>d.get(r)[1]){d.get(r)[1]=c2;}}longtracks=0;for(int[]range:d.values()){tracks+=range[1]-range[0]+1;}longlamps=total-tracks;returnlamps;}publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);// Read inputintn=scanner.nextInt();intm=scanner.nextInt();intk=scanner.nextInt();int[][]track=newint[k][3];for(inti=0;i<k;i++){track[i][0]=scanner.nextInt();track[i][1]=scanner.nextInt();track[i][2]=scanner.nextInt();}// Calculate and print the resultlongresult=gridlandMetro(n,m,k,track);System.out.println(result);scanner.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Gridland Metro
You are viewing a single comment's thread. Return to all comments →