답안 #553554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553554 2022-04-26T08:46:03 Z Awerar Nautilus (BOI19_nautilus) C++14
66 / 100
149 ms 262144 KB
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <limits.h>
#include <math.h>
#include <chrono>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define p2 pair<ll, ll>
#define p3 tuple<ll,ll,ll>
#define p4 vi
#define ip3 tuple<int,int,int>
#define ip4 tuple<int,int,int,int>
#define vp2 vector<p2>
#define vp3 vector<p3>
#define inf 2e9
#define linf 1e17

#define read(a) cin >> a
#define write(a) cout << (a) << "\n"
#define dread(type, a) type a; cin >> a
#define dread2(type, a, b) dread(type, a); dread(type, b)
#define dread3(type, a, b, c) dread2(type, a, b); dread(type, c)
#define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d)
#define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e)
#ifdef _DEBUG
#define deb __debugbreak();
#else
#define deb ;
#endif

#define rep(i, high) for (ll i = 0; i < high; i++)
#define repp(i, low, high) for (ll i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define per(i, high) for (ll i = high; i >= 0; i--)

#define readpush(type,vect) type temp; read(temp); vect.push_back(temp);
#define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;}
#define readinsert(type,a) {type temp; read(temp); a.insert(temp);}
#define all(a) begin(a),end(a)
#define setcontains(set, x) (set.find(x) != set.end())
#define stringcontains(str, x) (str.find(x) != string::npos)
#define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d)

#define ceildiv(x,y) ((x + y - 1) / y)
#define fract(a) (a-floor(a))
#define sign(a) ((a>0) ? 1 : -1)

auto Start = chrono::high_resolution_clock::now();

inline void fast()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

ll w, h, m;
vector<vector<bool>> grid;
vector<vector<vector<bool*>>> dp_table;
string instructions;

bool dp(int x, int y, int i) {
    if(x < 0 || x >= w || y < 0 || y >= h || grid[x][y]) return false;
    if(i < 0) return true;

    if(dp_table[x][y][i] != NULL) return *dp_table[x][y][i];

    string dirs = "";
    dirs += instructions[i];
    if(dirs[0] == '?') dirs = "EWNS";

    bool res = false;
    for(int j = 0; j < dirs.size(); j++) {
        switch (dirs[j])
        {
        case 'E': if(dp(x - 1, y, i - 1)) res = true; break;
        case 'W': if(dp(x + 1, y, i - 1)) res = true; break;
        case 'N': if(dp(x, y + 1, i - 1)) res = true; break;
        case 'S': if(dp(x, y - 1, i - 1)) res = true; break;
        }
    }

    dp_table[x][y][i] = new bool(res);
    return res;
}

int main() {
    //fast();

    cin >> h >> w >> m;
    grid.resize(w, vector<bool>(h));

    for(int y = 0; y < h; y++) {
        for(int x = 0; x < w; x++) {
            char c;
            cin >> c;

            grid[x][y] = c == '#';
        }
    }

    cin >> instructions;
    dp_table.resize(w, vector<vector<bool*>>(h, vector<bool*>(instructions.size(), NULL)));

    int answer = 0;
    rep(x, w) {
        rep(y, h) {
            if(dp(x, y, instructions.size() - 1)) answer++;
        }
    }

    cout << answer;
}

/*
5 9 7
...##....
..#.##..#
..#....##
.##...#..
....#....
WS?EE??

*/

Compilation message

nautilus.cpp:18: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   18 | #pragma GCC optimization ("O3")
      | 
nautilus.cpp:19: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   19 | #pragma GCC optimization ("unroll-loops")
      | 
nautilus.cpp: In function 'bool dp(int, int, int)':
nautilus.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int j = 0; j < dirs.size(); j++) {
      |                    ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 36428 KB Output is correct
2 Correct 11 ms 11316 KB Output is correct
3 Correct 7 ms 9556 KB Output is correct
4 Correct 6 ms 8756 KB Output is correct
5 Correct 5 ms 8628 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 36428 KB Output is correct
2 Correct 11 ms 11316 KB Output is correct
3 Correct 7 ms 9556 KB Output is correct
4 Correct 6 ms 8756 KB Output is correct
5 Correct 5 ms 8628 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 66 ms 39124 KB Output is correct
8 Correct 15 ms 13012 KB Output is correct
9 Correct 6 ms 9136 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 5 ms 8560 KB Output is correct
12 Correct 82 ms 39568 KB Output is correct
13 Correct 81 ms 31560 KB Output is correct
14 Correct 50 ms 22860 KB Output is correct
15 Correct 7 ms 9300 KB Output is correct
16 Correct 5 ms 8660 KB Output is correct
17 Correct 89 ms 39868 KB Output is correct
18 Correct 86 ms 33652 KB Output is correct
19 Correct 36 ms 19440 KB Output is correct
20 Correct 15 ms 12348 KB Output is correct
21 Correct 5 ms 8660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 36428 KB Output is correct
2 Correct 11 ms 11316 KB Output is correct
3 Correct 7 ms 9556 KB Output is correct
4 Correct 6 ms 8756 KB Output is correct
5 Correct 5 ms 8628 KB Output is correct
6 Correct 5 ms 8532 KB Output is correct
7 Correct 66 ms 39124 KB Output is correct
8 Correct 15 ms 13012 KB Output is correct
9 Correct 6 ms 9136 KB Output is correct
10 Correct 6 ms 8788 KB Output is correct
11 Correct 5 ms 8560 KB Output is correct
12 Correct 82 ms 39568 KB Output is correct
13 Correct 81 ms 31560 KB Output is correct
14 Correct 50 ms 22860 KB Output is correct
15 Correct 7 ms 9300 KB Output is correct
16 Correct 5 ms 8660 KB Output is correct
17 Correct 89 ms 39868 KB Output is correct
18 Correct 86 ms 33652 KB Output is correct
19 Correct 36 ms 19440 KB Output is correct
20 Correct 15 ms 12348 KB Output is correct
21 Correct 5 ms 8660 KB Output is correct
22 Runtime error 149 ms 262144 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -