結果
| 問題 | No.3504 Insert Maze |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 02:00:05 |
| 言語 | C (gcc 15.2.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,615 bytes |
| 記録 | |
| コンパイル時間 | 584 ms |
| コンパイル使用メモリ | 39,296 KB |
| 実行使用メモリ | 83,984 KB |
| 最終ジャッジ日時 | 2026-04-18 02:00:25 |
| 合計ジャッジ時間 | 18,781 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 85 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define MAXH 2005
#define MAXW 2005
static char g[MAXH][MAXW];
int main(void) {
int H, W;
scanf("%d %d", &H, &W);
for (int i = 0; i < H; i++) {
scanf("%s", g[i]);
}
int R = 2 * H - 1;
int C = 2 * W - 1;
int N = R * C;
unsigned char *vis = (unsigned char *)calloc(N, 1);
int *q = (int *)malloc(sizeof(int) * N);
if (!vis || !q) return 0;
int sr = 0, sc = 0;
int gr = R - 1, gc = C - 1;
int s = sr * C + sc;
int t = gr * C + gc;
int head = 0, tail = 0;
q[tail++] = s;
vis[s] = 1;
int dist = 0;
const int dr[4] = {-1, 1, 0, 0};
const int dc[4] = {0, 0, -1, 1};
while (head < tail) {
int qs = tail - head;
while (qs--) {
int v = q[head++];
if (v == t) {
printf("%d\n", dist);
free(vis);
free(q);
return 0;
}
int r = v / C;
int c = v % C;
for (int dir = 0; dir < 4; dir++) {
int nr = r + dr[dir];
int nc = c + dc[dir];
if (nr < 0 || nr >= R || nc < 0 || nc >= C) continue;
if ((nr % 2 == 0) && (nc % 2 == 0)) {
if (g[nr / 2][nc / 2] == '#') continue;
}
int ni = nr * C + nc;
if (vis[ni]) continue;
vis[ni] = 1;
q[tail++] = ni;
}
}
dist++;
}
printf("-1\n");
free(vis);
free(q);
return 0;
}