結果
問題 | No.367 ナイトの転身 |
ユーザー | FF256grhy |
提出日時 | 2016-04-30 00:08:07 |
言語 | C++11 (gcc 11.4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,521 bytes |
コンパイル時間 | 228 ms |
コンパイル使用メモリ | 24,320 KB |
実行使用メモリ | 11,612 KB |
最終ジャッジ日時 | 2024-10-04 19:49:57 |
合計ジャッジ時間 | 1,413 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
7,792 KB |
testcase_01 | AC | 1 ms
7,664 KB |
testcase_02 | AC | 1 ms
7,788 KB |
testcase_03 | AC | 1 ms
6,820 KB |
testcase_04 | AC | 1 ms
7,788 KB |
testcase_05 | AC | 1 ms
7,664 KB |
testcase_06 | AC | 1 ms
8,024 KB |
testcase_07 | AC | 1 ms
7,784 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
7,788 KB |
testcase_10 | AC | 11 ms
9,568 KB |
testcase_11 | AC | 18 ms
11,612 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | AC | 11 ms
8,464 KB |
testcase_15 | RE | - |
testcase_16 | AC | 10 ms
9,748 KB |
testcase_17 | AC | 2 ms
8,232 KB |
testcase_18 | AC | 2 ms
8,232 KB |
testcase_19 | AC | 3 ms
6,816 KB |
testcase_20 | AC | 3 ms
6,816 KB |
testcase_21 | AC | 4 ms
8,504 KB |
testcase_22 | AC | 1 ms
7,668 KB |
testcase_23 | AC | 1 ms
7,804 KB |
testcase_24 | AC | 2 ms
6,816 KB |
testcase_25 | AC | 1 ms
7,816 KB |
testcase_26 | AC | 1 ms
6,816 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d%d", &h, &w); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:25:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | for(int i = 0; i < h; i++) { scanf("%s", str[i]); } | ~~~~~^~~~~~~~~~~~~~ main.cpp:69:13: warning: ‘g_j’ may be used uninitialized in this function [-Wmaybe-uninitialized] 69 | int b = dp[1][g_i][g_j]; | ^ main.cpp:69:13: warning: ‘g_i’ may be used uninitialized in this function [-Wmaybe-uninitialized] main.cpp:37:22: warning: ‘s_j’ may be used uninitialized in this function [-Wmaybe-uninitialized] 37 | queue_j[set] = s_j; | ~~~~~~~~~~~~~^~~~~ main.cpp:36:22: warning: ‘s_i’ may be used uninitialized in this function [-Wmaybe-uninitialized] 36 | queue_i[set] = s_i; | ~~~~~~~~~~~~~^~~~~
ソースコード
#include <stdio.h> int h, w; char str[500][501]; int dp[2][500][500]; #define MAX 500 * 500 * 2 int queue_i[MAX]; int queue_j[MAX]; int queue_v[MAX]; // step (+1) int queue_s[MAX]; // knight : 0, bishop : 1 int set, get; int next_i[2][8] = { { -2, -2, -1, -1, +1, +1, +2, +2 }, { -1, -1, +1, +1 } }; int next_j[2][8] = { { -1, +1, -2, +2, -2, +2, -1, +1 }, { -1, +1, -1, +1 } }; int next_n[2] = { 8, 4 }; int in(int i, int j) { return 0 <= i && i < h && 0 <= j && j < w; } int main() { scanf("%d%d", &h, &w); for(int i = 0; i < h; i++) { scanf("%s", str[i]); } int s_i, s_j, g_i, g_j; for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { if(str[i][j] == 'S') { s_i = i; s_j = j; } if(str[i][j] == 'G') { g_i = i; g_j = j; } } } dp[2][s_i][s_j] = 1; queue_i[set] = s_i; queue_j[set] = s_j; queue_v[set] = 1; queue_s[set] = 0; set++; while(get != set) { int i, j, v, s; i = queue_i[get]; j = queue_j[get]; v = queue_v[get]; s = queue_s[get]; if(str[i][j] == 'R') { s = (! s); } for(int k = 0; k < next_n[s]; k++) { int ii = i + next_i[s][k]; int jj = j + next_j[s][k]; if( in(ii, jj) && dp[s][ii][jj] == 0 ) { dp[s][ii][jj] = v + 1; queue_i[set] = ii; queue_j[set] = jj; queue_v[set] = v + 1; queue_s[set] = s; set++; } } get++; } int ans; int k = dp[0][g_i][g_j]; int b = dp[1][g_i][g_j]; if( k == 0 || b == 0 ) { ans = k < b ? b : k; } else { ans = k < b ? k : b; } printf("%d\n", ans - 1); return 0; }