Submission #1116536

#TimeUsernameProblemLanguageResultExecution timeMemory
1116536xnqsNautilus (BOI19_nautilus)C++17
66 / 100
1046 ms2808 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2") #include <iostream> #include <fstream> #include <vector> #include <queue> #include <utility> #include <algorithm> #include <cstring> int x, y, p; char arr[505][505]; char moves[5005]; int dp[2][505][505]; const int dx[] = {0,1,0,-1}; const int dy[] = {1,0,-1,0}; void solve_dp() { for (int pos = 0; pos <= p; pos++) { memset(dp[pos&1],0,sizeof(dp[pos&1])); int curr_pos = pos&1; int last_pos = curr_pos^1; for (int i = 1; i <= x; i++) { for (int j = 1; j <= y; j++) { if (arr[i][j]=='#') { continue; } if (pos==0) { dp[curr_pos][i][j] = 1; continue; } switch (moves[pos-1]) { case 'N': dp[curr_pos][i][j] = dp[last_pos][i+1][j]; break; case 'S': dp[curr_pos][i][j] = dp[last_pos][i-1][j]; break; case 'E': dp[curr_pos][i][j] = dp[last_pos][i][j-1]; break; case 'W': dp[curr_pos][i][j] = dp[last_pos][i][j+1]; break; default: for (int k = 0; k < 4; k++) { int iv = i+dx[k]; int jv = j+dy[k]; dp[curr_pos][i][j] |= dp[last_pos][iv][jv]; if (dp[curr_pos][i][j]) { break; } } break; } } } } } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> x >> y >> p; for (int i = 1; i <= x; i++) { std::cin >> (arr[i]+1); } std::cin >> moves; solve_dp(); int ret = 0; for (int i = 1; i <= x; i++) { for (int j = 1; j <= y; j++) { ret += dp[p&1][i][j]; } } std::cout << ret << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...