Submission #496295

# Submission time Handle Problem Language Result Execution time Memory
496295 2021-12-21T05:08:48 Z Nalrimet Nautilus (BOI19_nautilus) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 5 * 1e2 + 5;
const int inf = 1000000000;

#define int long long
#define F first
#define S second
#define pb push_back
#define ppb pop_back

int r, c, m, ans;
bool block[N][N], ok[N][N][N * 10], used[N][N][N * 10];
char s[5005];


void rec(int x, int y, int step){
    used[x][y][step] = 1;
    if(step == 0){
        ok[x][y][step] = 1;
        return;
    }
    if(s[step] == '?'){
        if(!block[x + 1][y] && !used[x + 1][y][step - 1]) rec(x + 1, y, step - 1);
        if(ok[x + 1][y][step - 1]) ok[x][y][step] = 1;
        if(!block[x - 1][y] && !used[x - 1][y][step - 1]) rec(x - 1, y, step - 1);
        if(ok[x - 1][y][step - 1]) ok[x][y][step] = 1;
        if(!block[x][y + 1] && !used[x][y + 1][step - 1]) rec(x, y + 1, step - 1);
        if(ok[x][y + 1][step - 1]) ok[x][y][step] = 1;
        if(!block[x][y - 1] && !used[x][y - 1][step - 1]) rec(x, y - 1, step - 1);
        if(ok[x][y - 1][step - 1]) ok[x][y][step] = 1;
    }
    else if(s[step] == 'N'){
        if(!block[x + 1][y] && !used[x + 1][y][step - 1]) rec(x + 1, y, step - 1);
        if(ok[x + 1][y][step - 1]) ok[x][y][step] = 1;
    }
    else if(s[step] == 'S'){
        if(!block[x - 1][y] && !used[x - 1][y][step - 1]) rec(x - 1, y, step - 1);
        if(ok[x - 1][y][step - 1]) ok[x][y][step] = 1;
    }
    else if(s[step] == 'W'){
        if(!block[x][y + 1] && !used[x][y + 1][step - 1]) rec(x, y + 1, step - 1);
        if(ok[x][y + 1][step - 1]) ok[x][y][step] = 1;
    }
    else{
        if(!block[x][y - 1] && !used[x][y - 1][step - 1]) rec(x, y - 1, step - 1);
        if(ok[x][y - 1][step - 1]) ok[x][y][step] = 1;
    }
}

 main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> r >> c >> m;

    for(int i = 1; i <= r; ++i){
        block[i][0] = 1;
        block[i][c + 1] = 1;
        for(int j = 1; j <= c; ++j){
            char c1;
            cin >> c1;
            if(c1 == '#') block[i][j] = 1;
//            cout << block[i][j];
        }
//        cout << '\n';
    }

    for(int j = 1; j <= c; ++j){
        block[0][j] = 1;
        block[r + 1][j] = 1;
    }

    for(int i = 1; i <= m; ++i){
        cin >> s[i];
    }

    for(int i = 1; i <= r; ++i){
        for(int j = 1; j <= c; ++j){
            if(!block[i][j]){
//                cout << i << ' ' << j << '\n';
                rec(i, j, m);
                if(ok[i][j][m]) ans++;
            }
        }
    }

    cout << ans;

    return 0;

}

Compilation message

nautilus.cpp:53:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 |  main() {
      |  ^~~~
/usr/bin/ld: failed to convert GOTPCREL relocation; relink with --no-relax
collect2: error: ld returned 1 exit status