結果

問題 No.340 雪の足跡
ユーザー pekempeypekempey
提出日時 2016-01-29 23:05:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 200 ms / 1,000 ms
コード長 2,159 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 169,828 KB
実行使用メモリ 15,848 KB
最終ジャッジ日時 2023-10-21 17:19:34
合計ジャッジ時間 5,903 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,804 KB
testcase_01 AC 16 ms
15,804 KB
testcase_02 AC 20 ms
15,640 KB
testcase_03 AC 16 ms
15,804 KB
testcase_04 AC 16 ms
15,804 KB
testcase_05 AC 19 ms
15,636 KB
testcase_06 AC 16 ms
15,804 KB
testcase_07 AC 18 ms
15,804 KB
testcase_08 AC 16 ms
15,804 KB
testcase_09 AC 17 ms
15,804 KB
testcase_10 AC 15 ms
15,804 KB
testcase_11 AC 17 ms
15,804 KB
testcase_12 AC 16 ms
15,816 KB
testcase_13 AC 16 ms
15,804 KB
testcase_14 AC 23 ms
15,804 KB
testcase_15 AC 23 ms
15,848 KB
testcase_16 AC 24 ms
15,804 KB
testcase_17 AC 28 ms
15,804 KB
testcase_18 AC 24 ms
15,848 KB
testcase_19 AC 27 ms
15,804 KB
testcase_20 AC 147 ms
15,804 KB
testcase_21 AC 115 ms
15,804 KB
testcase_22 AC 19 ms
15,640 KB
testcase_23 AC 152 ms
15,804 KB
testcase_24 AC 130 ms
15,804 KB
testcase_25 AC 134 ms
15,804 KB
testcase_26 AC 34 ms
15,804 KB
testcase_27 AC 21 ms
15,804 KB
testcase_28 AC 31 ms
15,804 KB
testcase_29 AC 167 ms
15,808 KB
testcase_30 AC 119 ms
15,808 KB
testcase_31 AC 177 ms
15,812 KB
testcase_32 AC 200 ms
15,812 KB
testcase_33 AC 162 ms
15,812 KB
testcase_34 AC 199 ms
15,812 KB
testcase_35 AC 166 ms
15,812 KB
testcase_36 AC 165 ms
15,812 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |                         scanf("%d", &b);
      |                         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
typedef long long ll;

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	
	static int imos[1010][1010], imos2[1010][1010];
	rep(i, n) {
		int m;
		cin >> m;
		m++;
		vector<int> ys(m), xs(m);
		rep(j, m) {
			int b;
			scanf("%d", &b);
			int y = b / w;
			int x = b % w;
			ys[j] = y;
			xs[j] = x;
		}
		rep(j, m - 1) {
			int y1 = min(ys[j], ys[j + 1]);
			int x1 = min(xs[j], xs[j + 1]);
			int y2 = max(ys[j], ys[j + 1]);
			int x2 = max(xs[j], xs[j + 1]);
			if (y1 == y2) {
				imos[y1][x1]++;
				imos[y1][x2]--;
				imos[y2 + 1][x1]--;
				imos[y2 + 1][x2]++;
			} else {
				imos2[y1][x1]++;
				imos2[y1][x2 + 1]--;
				imos2[y2][x1]--;
				imos2[y2][x2 + 1]++;
			}
		}
	}
	rep(i, 1009) rep(j, 1009) imos[i][j + 1] += imos[i][j];
	rep(j, 1009) rep(i, 1009) imos[i + 1][j] += imos[i][j];
	rep(i, 1009) rep(j, 1009) imos2[i][j + 1] += imos2[i][j];
	rep(j, 1009) rep(i, 1009) imos2[i + 1][j] += imos2[i][j];

	queue<pair<int, int>> q;
	q.emplace(0, 0);

	static int dist[1010][1010];
	const int inf = 1e9;
	rep(i, 1010) rep(j, 1010) dist[i][j] = inf;
	dist[0][0] = 0;
	while (!q.empty()) {
		int y, x;
		tie(y, x) = q.front(); q.pop();

		int dy[] = { 0, 1, 0, -1 };
		int dx[] = { 1, 0, -1, 0 };
		rep(k, 4) {
			int ny = y + dy[k];
			int nx = x + dx[k];
			if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if (k == 0 && imos[y][x] <= 0) continue;
			if (k == 1 && imos2[y][x] <= 0) continue;
			if (k == 2 && imos[ny][nx] <= 0) continue;
			if (k == 3 && imos2[ny][nx] <= 0) continue;
			if (chmin(dist[ny][nx], dist[y][x] + 1)) {
				q.emplace(ny, nx);
			}
		}
	}
	int ans = dist[h - 1][w - 1];
	if (ans >= inf) {
		cout << "Odekakedekinai.." << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}
0