Gridland Metro

Sort by

recency

|

414 Discussions

|

  • + 0 comments

    Is it expected that the C++ boilerplate does not parse the input integers correctly and that we have to debug that as well?

  • + 0 comments

    Branded merchandise tied to "Gridland Metro" is gaining attention as the game continues to captivate its players. Fans can find a range of collectible items, from stylish apparel to limited-edition accessories, all designed to enhance the connection with the unique gameplay experience. Whether you’re a strategy enthusiast or just discovering the game’s charm, these branded products offer a way to express your fandom and bring a piece of Gridland Metro into everyday life.

  • + 0 comments

    // where i am doing wrong

    public static long gridlandMetro(int n, int m, int k, List<List<Integer>> track) {
        Map<Integer,int[]> realPath = new HashMap<>();
        long result = 0;
        for(int i =0;i<k;i++){
            List<Integer> l1 = track.get(i);
            int row = l1.get(0);
            int c1 = l1.get(1);
            int c2 = l1.get(2);
            if(realPath.containsKey(row)){
                 int[] coloums = realPath.get(row);
                int c21 = coloums[0];
                int c22 = coloums[1];
                if(c21>c1){
                   coloums[0] = c1;
                }
                if(c22<c2){
                    coloums[1] = c2;
                }
                realPath.put(row, coloums);
            }else{
                int[] coloums = new int[2];
                coloums[0] = c1;
                coloums[1] = c2;
                realPath.put(row, coloums);
            }
        }
        for(int i =1;i<=n;i++){
            if(realPath.containsKey(i)){
                int[] coloums = realPath.get(i);
                int c21 = coloums[0];
                int c22 = coloums[1];
                int incr = (m+c21)-(c22+1);
                result+=incr;
            }else{
                result+=m;
            }
        }
        return result;
    }
    
  • + 1 comment
    long gridlandMetro(long n, long m, int k, vector<vector<int>> track) {
        if (track.empty()) return n * m;
        long lamppost = 0;
        sort(track.begin(), track.end());
        int currentRow = track[0][0], trackCell = 0, lastEnd = 0, rowCounter = 1;
        for (int i=0; i < track.size(); i++) {
            if (track[i][0] != currentRow) {
                lamppost = lamppost + m - trackCell;
                currentRow = track[i][0];
                trackCell = 0;
                lastEnd = 0;
                rowCounter++;
            }
            if (i < track.size()-1 and track[i+1][0] == currentRow and track[i][1] == track[i+1][1]) continue;
            trackCell = trackCell + track[i][2] - track[i][1] + 1;
            trackCell = (track[i][1] <= lastEnd) ? (trackCell - min(lastEnd-track[i][1]+1, track[i][2]-track[i][1]+1)) : trackCell;
            lastEnd = max(lastEnd, track[i][2]);
        }
        lamppost = lamppost + m - trackCell + m * (n - rowCounter);
        return lamppost;
    }
    

    O(n) except for the sort line

  • + 1 comment
    from collections import defaultdict
    
    def gridlandMetro(n, m, k, track):
        
        row_record = defaultdict(list)
        for r, c1, c2 in track:
            if r not in row_record:
                row_record[r] = [c1, c2]
            else:
                st, ed = row_record[r][0], row_record[r][1]
                if c1 > ed:
                    row_record[r][1] += c2 - c1 + 1
                else:
                    row_record[r][1] = max(ed, c2)
                if c2 < st:
                    row_record[r][0] -= c2 - c1 + 1
                else:
                    row_record[r][0] = min(st, c1)
                
        total_num = n * m
        for st, ed in row_record.values():
            total_num -= ed - st + 1
            
        return total_num