結果

問題 No.340 雪の足跡
ユーザー hotpepsihotpepsi
提出日時 2016-01-29 23:49:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 68,584 KB
実行使用メモリ 23,172 KB
最終ジャッジ日時 2023-10-21 17:35:48
合計ジャッジ時間 14,854 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
23,144 KB
testcase_01 AC 7 ms
23,144 KB
testcase_02 AC 7 ms
23,148 KB
testcase_03 AC 7 ms
23,144 KB
testcase_04 AC 7 ms
23,148 KB
testcase_05 WA -
testcase_06 AC 7 ms
23,144 KB
testcase_07 AC 8 ms
23,148 KB
testcase_08 AC 8 ms
23,148 KB
testcase_09 AC 7 ms
23,144 KB
testcase_10 AC 7 ms
23,148 KB
testcase_11 AC 9 ms
23,148 KB
testcase_12 AC 9 ms
23,148 KB
testcase_13 AC 9 ms
23,148 KB
testcase_14 AC 41 ms
23,152 KB
testcase_15 AC 48 ms
23,156 KB
testcase_16 AC 32 ms
23,152 KB
testcase_17 AC 61 ms
23,156 KB
testcase_18 AC 51 ms
23,156 KB
testcase_19 AC 60 ms
23,156 KB
testcase_20 TLE -
testcase_21 AC 953 ms
23,144 KB
testcase_22 AC 7 ms
23,148 KB
testcase_23 AC 729 ms
23,144 KB
testcase_24 TLE -
testcase_25 AC 936 ms
23,148 KB
testcase_26 AC 67 ms
23,148 KB
testcase_27 AC 17 ms
23,148 KB
testcase_28 AC 65 ms
23,152 KB
testcase_29 TLE -
testcase_30 AC 530 ms
23,172 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair <int, int> II;
typedef priority_queue<II> Queue;

int main(int argc, char *argv[])
{
	int W, H, N;
	static int road[1000000][4];
	static int dist[1000000];
	memset(road, -1, sizeof(road));
	memset(dist, 0x80, sizeof(dist));
	int def = dist[0];
	cin >> W >> H >> N;
	for (int i = 0; i < N; ++i) {
		int M;
		cin >> M;
		int prev, pos;
		cin >> prev;
		for (int j = 0; j < M; ++j) {
			cin >> pos;
			int left = prev - (prev % W);
			int right = left + W - 1;
			if (pos < left) {
				while (prev > pos) {
					road[prev][0] = prev - W, road[prev - W][1] = prev;
					prev -= W;
				}
			} else if (pos > right) {
				while (prev < pos) {
					road[prev][1] = prev + W, road[prev + W][0] = prev;
					prev += W;
				}
			} else if (pos < prev) {
				while (prev > pos) {
					road[prev][2] = prev - 1, road[prev - 1][3] = prev;
					prev--;
				}
			} else {
				while (prev < pos) {
					road[prev][3] = prev + 1, road[prev + 1][2] = prev;
					prev++;
				}
			}
		}
	}
	Queue q;
	for (int d = 0; d < 4; ++d) {
		int next = road[W * H - 1][d];
		if (next >= 0) {
			q.push(II(-1, next));
		}
	}
	while (q.size() > 0) {
		II top = q.top();
		q.pop();
		int current = top.second;
		int cost = top.first;
		if (cost > dist[current]) {
			dist[current] = cost--;
			for (int d = 0; d < 4; ++d) {
				int next = road[current][d];
				if (next >= 0 && cost > dist[next]) {
					q.push(II(cost, next));
				}
			}
		}
	}
	if (dist[0] != def) {
		cout << -dist[0] << endl;
	} else {
		cout << "Odekakedekinai.." << endl;
	}
	return 0;
}
0