結果

問題 No.340 雪の足跡
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-02-26 15:34:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 169,412 KB
実行使用メモリ 20,660 KB
最終ジャッジ日時 2023-09-02 09:59:22
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,648 KB
testcase_01 AC 3 ms
11,644 KB
testcase_02 AC 2 ms
5,456 KB
testcase_03 AC 3 ms
11,760 KB
testcase_04 AC 3 ms
11,624 KB
testcase_05 AC 2 ms
5,448 KB
testcase_06 AC 3 ms
11,760 KB
testcase_07 AC 3 ms
9,696 KB
testcase_08 AC 4 ms
11,636 KB
testcase_09 AC 3 ms
9,644 KB
testcase_10 AC 4 ms
11,648 KB
testcase_11 AC 5 ms
11,840 KB
testcase_12 AC 4 ms
11,776 KB
testcase_13 AC 4 ms
11,976 KB
testcase_14 AC 11 ms
12,760 KB
testcase_15 AC 14 ms
12,788 KB
testcase_16 AC 11 ms
12,460 KB
testcase_17 AC 17 ms
14,900 KB
testcase_18 AC 15 ms
14,980 KB
testcase_19 AC 17 ms
14,856 KB
testcase_20 AC 126 ms
20,380 KB
testcase_21 AC 87 ms
12,272 KB
testcase_22 AC 11 ms
13,376 KB
testcase_23 WA -
testcase_24 AC 116 ms
20,412 KB
testcase_25 AC 135 ms
20,532 KB
testcase_26 AC 25 ms
12,800 KB
testcase_27 AC 7 ms
11,828 KB
testcase_28 AC 22 ms
12,616 KB
testcase_29 AC 133 ms
19,968 KB
testcase_30 AC 95 ms
19,812 KB
testcase_31 AC 140 ms
19,896 KB
testcase_32 AC 162 ms
20,336 KB
testcase_33 AC 130 ms
20,356 KB
testcase_34 AC 161 ms
20,476 KB
testcase_35 AC 145 ms
20,348 KB
testcase_36 AC 146 ms
20,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)





int W, H, N;
int M[1010];
int B[1010][1010];
//-----------------------------------------------------------------
int vec[1010][1010];
int hor[1010][1010];
void makeEdge() {
	rep(i, 0, N) {
		rep(j, 0, M[i]) {
			int a = B[i][j];
			int b = B[i][j + 1];

			if (a > b) swap(a, b);

			int ya = a / W; int xa = a % W;
			int yb = b / W; int xb = b % W;

			if (ya == yb) { // x軸での移動
				hor[ya][xa]++;
				hor[ya][xb + 1]--;
			} else { // y軸での移動
				vec[xa][ya]++;
				vec[xa][yb + 1]--;
			}
		}
	}

	rep(y, 0, H) rep(x, 1, W) hor[y][x] += hor[y][x - 1];
	rep(x, 0, W) rep(y, 1, H) vec[x][y] += vec[x][y - 1];

	//rep(y, 0, H) rep(x, 0, W) printf("hor[y = %d][x = %d] = %d\n", y, x, hor[y][x]);
	//rep(x, 0, W) rep(y, 0, H) printf("vec[x = %d][y = %d] = %d\n", x, y, vec[x][y]);
}
//-----------------------------------------------------------------
bool done[1010][1010];
int dist[1010][1010];
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { -1, 0, 1, 0 };
int bfs() {
	queue<int> que;
	done[0][0] = true;
	dist[0][0] = 0;
	que.push(0);

	while (!que.empty()) {
		int y = que.front() / 1010;
		int x = que.front() % 1010;
		que.pop();

		if (y == H - 1 && x == W - 1) return dist[y][x];

		rep(i, 0, 4) {
			int xx = x + dx[i];
			int yy = y + dy[i];
			if (xx < 0 || W <= xx) continue;
			if (yy < 0 || H <= yy) continue;
			
			if (i % 2 == 1) {
				if (0 == hor[y][x] || 0 == hor[yy][xx]) continue;
			} else {
				if (0 == vec[x][y] || 0 == vec[xx][yy]) continue;
			}

			if (done[yy][xx]) continue;

			done[yy][xx] = 1;
			dist[yy][xx] = dist[y][x] + 1;
			que.push(yy * 1010 + xx);
		}
	}

	return -1;
}
//-----------------------------------------------------------------
int main() {
	cin >> W >> H >> N;
	rep(i, 0, N) {
		scanf("%d", &M[i]);
		rep(j, 0, M[i] + 1) scanf("%d", &B[i][j]);
	}

	makeEdge();
	int ans = bfs();
	if (0 <= ans)
		cout << ans << endl;
	else
		cout << "Odekakedekinai.." << endl;
}
0