結果

問題 No.340 雪の足跡
ユーザー kapokapo
提出日時 2016-05-19 13:29:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,732 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 79,004 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2024-04-15 23:11:38
合計ジャッジ時間 18,033 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
11,392 KB
testcase_01 AC 8 ms
11,264 KB
testcase_02 AC 9 ms
11,392 KB
testcase_03 AC 9 ms
11,264 KB
testcase_04 AC 9 ms
11,136 KB
testcase_05 WA -
testcase_06 AC 8 ms
11,264 KB
testcase_07 AC 9 ms
11,136 KB
testcase_08 AC 8 ms
11,392 KB
testcase_09 AC 9 ms
11,136 KB
testcase_10 AC 8 ms
11,392 KB
testcase_11 AC 11 ms
11,392 KB
testcase_12 AC 10 ms
11,392 KB
testcase_13 AC 10 ms
11,264 KB
testcase_14 AC 31 ms
11,520 KB
testcase_15 AC 37 ms
11,520 KB
testcase_16 AC 30 ms
11,520 KB
testcase_17 AC 48 ms
11,520 KB
testcase_18 AC 39 ms
11,648 KB
testcase_19 AC 48 ms
11,776 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 AC 9 ms
11,136 KB
testcase_23 AC 732 ms
15,232 KB
testcase_24 TLE -
testcase_25 AC 965 ms
15,360 KB
testcase_26 AC 73 ms
12,032 KB
testcase_27 AC 18 ms
11,392 KB
testcase_28 AC 64 ms
11,648 KB
testcase_29 AC 691 ms
14,976 KB
testcase_30 AC 402 ms
13,696 KB
testcase_31 AC 735 ms
14,592 KB
testcase_32 AC 892 ms
15,232 KB
testcase_33 AC 671 ms
14,080 KB
testcase_34 AC 886 ms
15,360 KB
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
#include <vector>
#include <map>

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
using namespace std;

int main(void)
{
	int w, h, n, t1, t2, x1, y1, x2, y2, x, y, i, j;
	cin >> w >> h >> n;
	vector<int> v;
	vector<vector<int> > lt;
	rep(i, 0, n) {
		v.clear();
		cin >> t1;
		rep(j, 0, t1+1) { cin >> t2; v.pb(t2); }
		lt.pb(v);
	}

	int bf[4] = {1,2,4,8}; // N E W S
	vector<vector<int> > dp(1000, vector<int>(1000, 0));
	vector<vector<int> > mp(1000, vector<int>(1000, 0));

	for(auto vec : lt) {
		rep(j, 0, (int)vec.size()-1) {
			y1 = vec[j]/w; x1 = vec[j]%w;
			y2 = vec[j+1]/w; x2 = vec[j+1]%w;
			if(y1 == y2) {
				if(x1 < x2) {
					rep(i,0,x2-x1) {
						mp[y1][x1+i] |= bf[1];
						mp[y1][x1+1+i] |= bf[2];
					}
				}
				else if(x1 > x2) {
					rep(i,0,x1-x2) {
						mp[y1][x1-i] |= bf[2];
						mp[y1][x1-1-i] |= bf[1];
					}
				}
			}
			else if(x1 == x2) {
				if(y1 < y2) {
					rep(i,0,y2-y1) {
						mp[y1+i][x1] |= bf[0];
						mp[y1+1+i][x1] |= bf[3];
					}
				}
				else if(y1 > y2) {
					rep(i,0,y1-y2) {
						mp[y1-i][x1] |= bf[3];
						mp[y1-1-i][x1] |= bf[0];
					}
				}
			}
		}
	}

	pair<int, int> p;
	queue<pair<int, int> > q;
	q.push(pair<int, int>(0,0));
	int ym[4] = {1, 0, 0, -1};
	int xm[4] = {0, 1, -1, 0};

	while(q.size()) {
		p = q.front();
		y = p.first; x = p.second;
		q.pop();

		rep(i,0,4) {
			if(!(mp[y][x] & bf[i])) continue;
			if(dp[y + ym[i]][x + xm[i]] == 0 || dp[ y+ym[i] ][ x+xm[i] ] > dp[y][x]+1) {
				dp[y + ym[i]][x + xm[i]] = dp[y][x] + 1;
				p.first = y+ym[i]; p.second = x+xm[i];
				q.push(p);
			}
		}
	}

	dp[h-1][w-1]? cout << dp[h-1][w-1] << endl : cout << "Odekakedekinai.." << endl;

	return 0;
}
0