結果
問題 | No.1572 XI |
ユーザー | 👑 ygussany |
提出日時 | 2021-06-27 13:54:12 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 2,302 bytes |
コンパイル時間 | 344 ms |
コンパイル使用メモリ | 31,616 KB |
実行使用メモリ | 71,552 KB |
最終ジャッジ日時 | 2024-06-25 11:31:28 |
合計ジャッジ時間 | 5,745 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 45 |
ソースコード
#include <stdio.h> int q[6000000][3]; int main() { int i, H, W, s[2], g[2]; char A[1002][1002] = {}; scanf("%d %d", &H, &W); scanf("%d %d", &(s[0]), &(s[1])); scanf("%d %d", &(g[0]), &(g[1])); for (i = 1; i <= H; i++) scanf("%s", &(A[i][1])); const int sup = 1 << 30; int j, k, l, dist[6][1001][1001], head, tail; for (k = 0; k < 6; k++) for (i = 1; i <= H; i++) for (j = 1; j <= W; j++) dist[k][i][j] = sup; dist[0][s[0]][s[1]] = 0; q[0][0] = 0; q[0][1] = s[0]; q[0][2] = s[1]; for (head = 0, tail = 1; head < tail; head++) { k = q[head][0]; i = q[head][1]; j = q[head][2]; if (A[i-1][j] == '.') { switch (k) { case 0: l = 1; break; case 1: l = 5; break; case 2: l = 2; break; case 3: l = 0; break; case 4: l = 4; break; case 5: l = 3; break; } if (dist[l][i-1][j] == sup) { dist[l][i-1][j] = dist[k][i][j] + 1; q[tail][0] = l; q[tail][1] = i - 1; q[tail++][2] = j; } } if (A[i+1][j] == '.') { switch (k) { case 0: l = 3; break; case 1: l = 0; break; case 2: l = 2; break; case 3: l = 5; break; case 4: l = 4; break; case 5: l = 1; break; } if (dist[l][i+1][j] == sup) { dist[l][i+1][j] = dist[k][i][j] + 1; q[tail][0] = l; q[tail][1] = i + 1; q[tail++][2] = j; } } if (A[i][j-1] == '.') { switch (k) { case 0: l = 4; break; case 1: l = 1; break; case 2: l = 0; break; case 3: l = 3; break; case 4: l = 5; break; case 5: l = 2; break; } if (dist[l][i][j-1] == sup) { dist[l][i][j-1] = dist[k][i][j] + 1; q[tail][0] = l; q[tail][1] = i; q[tail++][2] = j - 1; } } if (A[i][j+1] == '.') { switch (k) { case 0: l = 2; break; case 1: l = 1; break; case 2: l = 5; break; case 3: l = 3; break; case 4: l = 0; break; case 5: l = 4; break; } if (dist[l][i][j+1] == sup) { dist[l][i][j+1] = dist[k][i][j] + 1; q[tail][0] = l; q[tail][1] = i; q[tail++][2] = j + 1; } } } if (dist[0][g[0]][g[1]] == sup) printf("-1\n"); else printf("%d\n", dist[0][g[0]][g[1]]); fflush(stdout); return 0; }