답안 #328787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
328787 2020-11-18T05:12:20 Z egas Nautilus (BOI19_nautilus) C++14
66 / 100
53 ms 18412 KB
#include <bits/stdc++.h>

using namespace std;

bool vis[101][101];

long long dp[101][101][101];

set<pair<long long,long long> > ss;

long long solve(long long r,long long c,long long pt,vector<string> &grid,string &path) {

    if(r<0 or r>=grid.size() or c<0 or c>=grid[0].size())return 0;

    if(grid[r][c]!='.')return 0;

    if(pt==path.size()) {

        if(dp[r][c][pt]!=-1) {

            return 0;

        }

        dp[r][c][pt]=1;

        return 1;

    }

    if(dp[r][c][pt]!=-1) {

        return 0;

    }

    if(path[pt]=='?') {

        dp[r][c][pt] = solve(r,c-1,pt+1,grid,path) + solve(r,c+1,pt+1,grid,path) + solve(r-1,c,pt+1,grid,path) + solve(r+1,c,pt+1,grid,path);

        return dp[r][c][pt];

    } else {

        if(path[pt]=='W') {

            dp[r][c][pt]= solve(r,c-1,pt+1,grid,path);

            return dp[r][c][pt];

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

            dp[r][c][pt] = solve(r,c+1,pt+1,grid,path);

            return dp[r][c][pt];

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

            dp[r][c][pt]= solve(r-1,c,pt+1,grid,path);

            return dp[r][c][pt];

        } else if(path[pt]=='S') {

            dp[r][c][pt]= solve(r+1,c,pt+1,grid,path);

            return dp[r][c][pt];

        } else {

            assert(0);

        }

    }

    return 0;

}

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long r;

    cin >> r;

    long long c;

    cin >> c;

    long long m;

    cin >> m;

    vector<string> grid;

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

        string temp;

        cin >> temp;

        grid.push_back(temp);

    }

    string path;

    cin >> path;

    memset(dp,-1,sizeof dp);

    long long res=0;

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

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

            res+=solve(i,j,0,grid,path);

        }

    }

    cout << res << '\n';

    return 0;

}

Compilation message

nautilus.cpp: In function 'long long int solve(long long int, long long int, long long int, std::vector<std::__cxx11::basic_string<char> >&, std::string&)':
nautilus.cpp:13:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if(r<0 or r>=grid.size() or c<0 or c>=grid[0].size())return 0;
      |               ~^~~~~~~~~~~~~
nautilus.cpp:13:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     if(r<0 or r>=grid.size() or c<0 or c>=grid[0].size())return 0;
      |                                        ~^~~~~~~~~~~~~~~~
nautilus.cpp:17:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if(pt==path.size()) {
      |        ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 8428 KB Output is correct
2 Correct 8 ms 8428 KB Output is correct
3 Correct 6 ms 8428 KB Output is correct
4 Correct 6 ms 8428 KB Output is correct
5 Correct 5 ms 8428 KB Output is correct
6 Correct 5 ms 8428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 8428 KB Output is correct
2 Correct 8 ms 8428 KB Output is correct
3 Correct 6 ms 8428 KB Output is correct
4 Correct 6 ms 8428 KB Output is correct
5 Correct 5 ms 8428 KB Output is correct
6 Correct 5 ms 8428 KB Output is correct
7 Correct 33 ms 8428 KB Output is correct
8 Correct 11 ms 8428 KB Output is correct
9 Correct 7 ms 8428 KB Output is correct
10 Correct 6 ms 8428 KB Output is correct
11 Correct 5 ms 8556 KB Output is correct
12 Correct 52 ms 8428 KB Output is correct
13 Correct 38 ms 8428 KB Output is correct
14 Correct 26 ms 8428 KB Output is correct
15 Correct 6 ms 8428 KB Output is correct
16 Correct 5 ms 8428 KB Output is correct
17 Correct 53 ms 8492 KB Output is correct
18 Correct 45 ms 8428 KB Output is correct
19 Correct 16 ms 8428 KB Output is correct
20 Correct 9 ms 8428 KB Output is correct
21 Correct 5 ms 8428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 8428 KB Output is correct
2 Correct 8 ms 8428 KB Output is correct
3 Correct 6 ms 8428 KB Output is correct
4 Correct 6 ms 8428 KB Output is correct
5 Correct 5 ms 8428 KB Output is correct
6 Correct 5 ms 8428 KB Output is correct
7 Correct 33 ms 8428 KB Output is correct
8 Correct 11 ms 8428 KB Output is correct
9 Correct 7 ms 8428 KB Output is correct
10 Correct 6 ms 8428 KB Output is correct
11 Correct 5 ms 8556 KB Output is correct
12 Correct 52 ms 8428 KB Output is correct
13 Correct 38 ms 8428 KB Output is correct
14 Correct 26 ms 8428 KB Output is correct
15 Correct 6 ms 8428 KB Output is correct
16 Correct 5 ms 8428 KB Output is correct
17 Correct 53 ms 8492 KB Output is correct
18 Correct 45 ms 8428 KB Output is correct
19 Correct 16 ms 8428 KB Output is correct
20 Correct 9 ms 8428 KB Output is correct
21 Correct 5 ms 8428 KB Output is correct
22 Runtime error 45 ms 18412 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -