Submission #2945329
Source Code Expand
/** * File : E.cpp * Author : Kazune Takahashi * Created : 2018-8-4 22:09:58 * Powered by Visual Studio Code */ #include <iostream> #include <iomanip> // << fixed << setprecision(xxx) #include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ; #include <vector> #include <string> // to_string(nnn) // substr(m, n) // stoi(nnn) #include <complex> #include <tuple> #include <queue> #include <stack> #include <map> // if (M.find(key) != M.end()) { } #include <set> #include <functional> #include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725)); #include <chrono> // std::chrono::system_clock::time_point start_time, end_time; // start = std::chrono::system_clock::now(); // double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count(); #include <cctype> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> using namespace std; #define DEBUG 0 // change 0 -> 1 if we need debug. typedef long long ll; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const char ds[4] = {'D', 'R', 'U', 'L'}; typedef tuple<ll, int, int> state; // const int C = 1e6+10; const ll infty = 1000000007; int N, M, K; string D; string S[1010]; ll dist[200010][4]; ll ans[1010][1010]; int main() { cin >> N >> M >> K; cin >> D; D = D + D + D; for (auto i = 0; i < N; i++) { cin >> S[i]; } for (auto k = 0; k < 4; k++) { dist[2 * K][k] = infty; } for (int i = 2 * K - 1; i >= 0; i--) { for (auto k = 0; k < 4; k++) { if (D[i] == ds[k]) { dist[i][k] = 1; } else { dist[i][k] = dist[i + 1][k] + 1; } } } /* for (auto i = 0; i < K; i++) { for (auto k = 0; k < 4; k++) { cerr << "dist[" << i << "][" << k << "] = " << dist[i][k] << endl; } } */ int sx, sy, gx, gy; fill(&ans[0][0], &ans[0][0] + 1010 * 1010, -1); for (auto i = 0; i < N; i++) { for (auto j = 0; j < M; j++) { if (S[i][j] == 'S') { sx = i; sy = j; } else if (S[i][j] == 'G') { gx = i; gy = j; } } } priority_queue<state, vector<state>, greater<state>> Q; Q.push(state(0, sx, sy)); while (!Q.empty()) { ll d = get<0>(Q.top()); int x = get<1>(Q.top()); int y = get<2>(Q.top()); Q.pop(); if (ans[x][y] == -1) { ans[x][y] = d; // cerr << "ans[" << x << "][" << y << "] = " << ans[x][y] << endl; if (x == gx && y == gy) { cout << d << endl; return 0; } for (auto k = 0; k < 4; k++) { int new_x = x + dx[k]; int new_y = y + dy[k]; if (0 <= new_x && new_x < N && 0 <= new_y && new_y < M && S[new_x][new_y] != '#' && ans[new_x][new_y] == -1) { ll new_d = d + dist[d % K][k]; if (new_d < infty) { Q.push(state(new_d, new_x, new_y)); } } } } } cout << -1 << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - 迷路 |
User | kazunetakahashi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3172 Byte |
Status | WA |
Exec Time | 200 ms |
Memory | 16060 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 500 | ||||
Status | AC |
|
Set Name | Test Cases |
---|---|
Sample | |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, s1.txt, s2.txt, s3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 4 ms | 8448 KB |
02.txt | AC | 4 ms | 8448 KB |
03.txt | AC | 4 ms | 8448 KB |
04.txt | AC | 4 ms | 8448 KB |
05.txt | AC | 4 ms | 8448 KB |
06.txt | AC | 173 ms | 16060 KB |
07.txt | AC | 143 ms | 15932 KB |
08.txt | AC | 161 ms | 15932 KB |
09.txt | AC | 149 ms | 15932 KB |
10.txt | AC | 139 ms | 16060 KB |
11.txt | AC | 141 ms | 15932 KB |
12.txt | AC | 200 ms | 16060 KB |
13.txt | AC | 171 ms | 15932 KB |
14.txt | AC | 197 ms | 16060 KB |
15.txt | AC | 165 ms | 15932 KB |
16.txt | AC | 48 ms | 15932 KB |
17.txt | AC | 102 ms | 15932 KB |
18.txt | AC | 94 ms | 16060 KB |
19.txt | AC | 67 ms | 15932 KB |
20.txt | AC | 140 ms | 16060 KB |
21.txt | AC | 187 ms | 15932 KB |
22.txt | AC | 191 ms | 15932 KB |
23.txt | AC | 183 ms | 15932 KB |
24.txt | AC | 185 ms | 15932 KB |
25.txt | AC | 184 ms | 15932 KB |
26.txt | AC | 187 ms | 15932 KB |
27.txt | AC | 183 ms | 15932 KB |
28.txt | AC | 187 ms | 15932 KB |
29.txt | AC | 185 ms | 15932 KB |
30.txt | AC | 183 ms | 15932 KB |
31.txt | AC | 43 ms | 15804 KB |
32.txt | AC | 43 ms | 15804 KB |
33.txt | AC | 43 ms | 15804 KB |
34.txt | AC | 43 ms | 15804 KB |
35.txt | AC | 43 ms | 15804 KB |
36.txt | AC | 43 ms | 15804 KB |
37.txt | AC | 43 ms | 15804 KB |
38.txt | AC | 43 ms | 15804 KB |
39.txt | AC | 43 ms | 15804 KB |
40.txt | WA | 44 ms | 15804 KB |
41.txt | AC | 3 ms | 8448 KB |
s1.txt | AC | 3 ms | 8448 KB |
s2.txt | AC | 4 ms | 8448 KB |
s3.txt | AC | 4 ms | 8448 KB |