結果
| 問題 |
No.367 ナイトの転身
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2016-04-30 00:13:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,522 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 23,936 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-04 23:23:39 |
| 合計ジャッジ時間 | 1,397 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 1 RE * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:26:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | for(int i = 0; i < h; i++) { scanf("%s", str[i]); }
| ~~~~~^~~~~~~~~~~~~~
main.cpp:70:13: warning: ‘g_j’ may be used uninitialized in this function [-Wmaybe-uninitialized]
70 | int b = dp[1][g_i][g_j];
| ^
main.cpp:70:13: warning: ‘g_i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
main.cpp:38:22: warning: ‘s_j’ may be used uninitialized in this function [-Wmaybe-uninitialized]
38 | queue_j[set] = s_j;
| ~~~~~~~~~~~~~^~~~~
main.cpp:37:22: warning: ‘s_i’ may be used uninitialized in this function [-Wmaybe-uninitialized]
37 | queue_i[set] = s_i;
| ~~~~~~~~~~~~~^~~~~
ソースコード
#include <stdio.h>
int h, w;
char str[500][501];
int dp[2][500][500];
// test
#define MAX 100000
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;
}
FF256grhy