제출 #328831

#제출 시각아이디문제언어결과실행 시간메모리
328831egasNautilus (BOI19_nautilus)C++14
66 / 100
1077 ms1132 KiB
#include <bits/stdc++.h>

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    int r;

    cin >> r;

    int c;

    cin >> c;

    int m;

    cin >> m;

    vector<string> grid;

    for(int i = 0 ; i < r ; i++) {

        string temp;

        cin >> temp;

        grid.push_back(temp);

    }

    string path;

    cin >> path;

    bool canVisit[501][501][2];

    memset(canVisit,0,sizeof canVisit);

    int res=0;

    for(int i = 0 ; i < r ; i++) {

        for(int j = 0 ; j < c ; j++) {

            if(grid[i][j]=='.') {

                canVisit[i][j][0]=true;

            }

        }

    }

    for(int k=0; k<path.length(); k++) {

        if(path[k]=='S') {

            for(int i = 0 ; i < r ; i++) {

                for(int j = 0 ; j < c ; j++) {

                    if(i-1>=0 and canVisit[i-1][j][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                }

            }

        } else if(path[k]=='N') {

            for(int i = 0 ; i < r ; i++) {

                for(int j = 0 ; j < c ; j++) {

                    if(i+1<r and canVisit[i+1][j][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                }

            }

        } else if(path[k]=='E') {

            for(int i = 0 ; i < r ; i++) {

                for(int j = 0 ; j < c ; j++) {

                    if(j-1>=0 and canVisit[i][j-1][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                }

            }

        } else if(path[k]=='W') {

            for(int i = 0 ; i < r ; i++) {

                for(int j = 0 ; j < c ; j++) {

                    if(j+1<c and canVisit[i][j+1][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                }

            }

        } else {

            for(int i = 0 ; i < r ; i++) {

                for(int j = 0 ; j < c ; j++) {

                    if(i-1>=0 and canVisit[i-1][j][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                    if(i+1<r and canVisit[i+1][j][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                    if(j+1<c and canVisit[i][j+1][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                    if(j-1>=0 and canVisit[i][j-1][0] and grid[i][j]=='.') {

                        canVisit[i][j][1]=1;

                    }

                }

            }

        }

        for(int i = 0 ; i < r ; i++) {

            for(int j = 0 ; j < c ; j++) {

                canVisit[i][j][0]=canVisit[i][j][1];

                canVisit[i][j][1]=0;

            }

        }

    }

    for(int i = 0 ; i < r ; i++) {

        for(int j = 0 ; j < c ; j++) {

            res+=canVisit[i][j][0];

        }

    }

    cout << res << '\n';

    return 0;

}

컴파일 시 표준 에러 (stderr) 메시지

nautilus.cpp: In function 'int32_t main()':
nautilus.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int k=0; k<path.length(); k++) {
      |                  ~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...