Submission #95564

# Submission time Handle Problem Language Result Execution time Memory
95564 2019-02-02T05:30:10 Z oolimry Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
38 ms 5548 KB
#include <bits/stdc++.h>

using namespace std;

class Grid{
public:
    int rows, columns;
    vector< vector<int> > grid;
    vector<int> IntMapping;
    vector<char> CharMapping;
    void create(){
        for(int r = 0;r < rows;r++){
            vector<int> v;
            for(int c = 0;c < columns;c++){
                v.push_back(9);
            }
            grid.push_back(v);
        }
    }
    void readChar(){
        for(int r = 0;r < rows;r++){
            char ch;
            scanf("%c",&ch);
            for(int c = 0;c < columns;c++){
                scanf("%c",&ch);
                for(int i = 0;i < CharMapping.size();i++){
                    if(CharMapping[i] == ch){
                        grid[r][c] = i;
                    }
                }
            }
        }
    }
    bool isOut(int r, int c){
        return (r < 0 || c < 0 || r >= rows || c >= columns);

    }
    int get(int r,int c){
        if(isOut(r,c))
            return 1;
        return grid[r][c];


    }
    void showGrid(){
        for(int r = 0;r < rows;r++){
            for(int c = 0;c < columns;c++){
                printf("%d ",grid[r][c]);
            }
            printf("\n");
        }
    }
};

int main()
{
    //freopen("i4.txt","r",stdin);
    int r, c, d, k;
    scanf("%d %d %d %d",&r,&c,&d,&k);
    Grid g;
    g.rows  = r;
    g.columns = c;
    g.create();
    g.CharMapping.push_back('.');
    g.CharMapping.push_back('S');
    g.CharMapping.push_back('M');
    g.readChar();

    int prefix[r][c];

    for(int rr = 0;rr < r;rr++){
        for(int cc = 0;cc < c;cc++){
            if(g.grid[rr][cc] == 2){
                prefix[rr][cc] = 0;
            }
            else{
                prefix[rr][cc] = g.grid[rr][cc];
            }
        }
    }
    //g.showGrid();
    for(int rr = 0;rr < r;rr++){
        for(int cc = 1;cc < c;cc++){
            prefix[rr][cc] += prefix[rr][cc-1];
        }
    }

    for(int rr = 1;rr < r;rr++){
        for(int cc = 0;cc < c;cc++){
            prefix[rr][cc] += prefix[rr-1][cc];
        }
    }

    int canMush = 0;
    for(int rr = 0;rr < r;rr++){
        for(int cc = 0;cc < c;cc++){
            if(g.grid[rr][cc] != 2){
                continue;
            }
            else{
                int top = max(0, rr - d);
                int bottom = min(r - 1,rr + d);
                int left = max(0, cc - d);
                int right = min(c - 1,cc + d);


                int n = 0;
                n += prefix[bottom][right];
                if(top > 0){
                    n -= prefix[top-1][right];
                }
                if(left > 0){
                    n -= prefix[bottom][left-1];
                }
                if(top > 0 && left > 0){
                    n += prefix[top-1][left-1];
                }

                if(n >= k){
                    canMush++;
                }
                //printf("%d %d %d %d %d\n",left,right,top,bottom,n);
            }
        }
    }

    printf("%d",canMush);

    for(int rr = 0;rr < r;rr++){
        for(int cc = 0;cc < c;cc++){
            //printf("%d ",prefix[rr][cc]);
        }
        //printf("\n");
    }
    return 0;
}

Compilation message

mushrooms.cpp: In member function 'void Grid::readChar()':
mushrooms.cpp:26:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int i = 0;i < CharMapping.size();i++){
                               ~~^~~~~~~~~~~~~~~~~~~~
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d",&r,&c,&d,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp: In member function 'void Grid::readChar()':
mushrooms.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%c",&ch);
             ~~~~~^~~~~~~~~~
mushrooms.cpp:25:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%c",&ch);
                 ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2040 KB Output is correct
2 Correct 13 ms 2168 KB Output is correct
3 Correct 15 ms 2552 KB Output is correct
4 Correct 13 ms 2168 KB Output is correct
5 Correct 14 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 4796 KB Output is correct
2 Correct 33 ms 4796 KB Output is correct
3 Correct 34 ms 4880 KB Output is correct
4 Correct 34 ms 4796 KB Output is correct
5 Correct 33 ms 4796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 13 ms 2040 KB Output is correct
17 Correct 13 ms 2168 KB Output is correct
18 Correct 15 ms 2552 KB Output is correct
19 Correct 13 ms 2168 KB Output is correct
20 Correct 14 ms 2296 KB Output is correct
21 Correct 34 ms 4796 KB Output is correct
22 Correct 33 ms 4796 KB Output is correct
23 Correct 34 ms 4880 KB Output is correct
24 Correct 34 ms 4796 KB Output is correct
25 Correct 33 ms 4796 KB Output is correct
26 Correct 38 ms 5548 KB Output is correct
27 Correct 32 ms 4720 KB Output is correct
28 Correct 32 ms 4600 KB Output is correct
29 Correct 31 ms 4728 KB Output is correct
30 Correct 36 ms 5304 KB Output is correct