結果
問題 | No.367 ナイトの転身 |
ユーザー | sugim48 |
提出日時 | 2016-04-29 23:09:09 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 1,985 bytes |
コンパイル時間 | 748 ms |
コンパイル使用メモリ | 91,536 KB |
実行使用メモリ | 40,808 KB |
最終ジャッジ日時 | 2024-10-04 18:46:32 |
合計ジャッジ時間 | 1,935 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 123 ms
40,760 KB |
testcase_11 | AC | 126 ms
40,808 KB |
testcase_12 | AC | 54 ms
17,536 KB |
testcase_13 | AC | 49 ms
17,756 KB |
testcase_14 | AC | 51 ms
16,980 KB |
testcase_15 | AC | 3 ms
5,248 KB |
testcase_16 | AC | 46 ms
15,360 KB |
testcase_17 | AC | 6 ms
5,248 KB |
testcase_18 | AC | 9 ms
5,248 KB |
testcase_19 | AC | 14 ms
7,168 KB |
testcase_20 | AC | 7 ms
5,248 KB |
testcase_21 | AC | 15 ms
6,912 KB |
testcase_22 | AC | 1 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:52:23: warning: ‘xt’ may be used uninitialized in this function [-Wmaybe-uninitialized] 52 | return (y * W + x) * 2 + z; | ~~~~~~~^~~~ main.cpp:58:25: note: ‘xt’ was declared here 58 | int ys, xs, yt, xt; | ^~ main.cpp:52:19: warning: ‘yt’ may be used uninitialized in this function [-Wmaybe-uninitialized] 52 | return (y * W + x) * 2 + z; | ~~^~~ main.cpp:58:21: note: ‘yt’ was declared here 58 | int ys, xs, yt, xt; | ^~ main.cpp:52:23: warning: ‘xs’ may be used uninitialized in this function [-Wmaybe-uninitialized] 52 | return (y * W + x) * 2 + z; | ~~~~~~~^~~~ main.cpp:58:17: note: ‘xs’ was declared here 58 | int ys, xs, yt, xt; | ^~ main.cpp:52:19: warning: ‘ys’ may be used uninitialized in this function [-Wmaybe-uninitialized] 52 | return (y * W + x) * 2 + z; | ~~^~~ main.cpp:58:13: note: ‘ys’ was declared here 58 | int ys, xs, yt, xt; | ^~
ソースコード
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<ll, int> ll_i; typedef pair<double, int> d_i; typedef pair<ll, ll> ll_ll; typedef pair<double, double> d_d; struct edge { int u, v; ll w; }; int INF = INT_MAX / 2; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; vector<int> bfs(int N, vector<vector<int> >& G, int s) { vector<int> d(N, INF); d[s] = 0; queue<int> q; q.push(s); while (q.size()) { int u = q.front(); q.pop(); for (int v: G[u]) if (d[v] > d[u] + 1) { d[v] = d[u] + 1; q.push(v); } } return d; } int H, W; int f(int y, int x, int z) { return (y * W + x) * 2 + z; } int main() { cin >> H >> W; vector<string> a(H); int ys, xs, yt, xt; for (int y = 0; y < H; y++) { cin >> a[y]; for (int x = 0; x < W; x++) { char& c = a[y][x]; if (c == 'S') ys = y, xs = x, c = '.'; if (c == 'G') yt = y, xt = x, c = '.'; } } int N = H * W * 2; vector<vector<int> > G(N); for (int y = 0; y < H; y++) for (int x = 0; x < W; x++) for (int z = 0; z <= 1; z++) { int dy[2][8] = {{-1, -2, -2, -1, 1, 2, 2, 1}, {-1, -1, 1, 1, -1, -1, 1, 1}}; int dx[2][8] = {{-2, -1, 1, 2, 2, 1, -1, -2}, {-1, 1, 1, -1, -1, 1, 1, -1}}; for (int k = 0; k < 8; k++) { int _y = y + dy[z][k], _x = x + dx[z][k]; if (_y >= 0 && _y < H && _x >= 0 && _x < W) { int _z = z; if (a[_y][_x] == 'R') _z ^= 1; G[f(y, x, z)].push_back(f(_y, _x, _z)); } } } vector<int> d = bfs(N, G, f(ys, xs, 0)); int ans = min(d[f(yt, xt, 0)], d[f(yt, xt, 1)]); if (ans == INF) ans = -1; cout << ans << endl; }