結果

問題 No.340 雪の足跡
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-09 14:35:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,570 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 70,192 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-04-24 23:00:39
合計ジャッジ時間 4,766 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,928 KB
testcase_01 AC 5 ms
7,552 KB
testcase_02 AC 5 ms
7,424 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
7,424 KB
testcase_07 AC 5 ms
7,424 KB
testcase_08 AC 5 ms
7,424 KB
testcase_09 AC 4 ms
7,552 KB
testcase_10 WA -
testcase_11 AC 7 ms
7,552 KB
testcase_12 AC 6 ms
7,808 KB
testcase_13 AC 7 ms
7,552 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

//横縦横縦
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<int> b[1001];
bool boardy[1001][1001];//y方向への動けるか
bool boardx[1001][1001];
int memo[1001][1001];//(0, 0)からの最短経路を保存しておく
int main(void){
	int w, h, n; cin >> w >> h >> n;
	rep(i, n){
		int m; cin >> m;
		rep(j, m + 1){
			int tmp; cin >> tmp;
			b[i].push_back(tmp);
		}
	}

	//通れる道を探す
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < b[i].size() - 1; ++j){
			int ma, mi;
			if(b[i][j] > b[i][j + 1]){
				ma = b[i][j]; mi = b[i][j + 1];
			}else{
				mi = b[i][j]; ma = b[i][j + 1];
			}
			if((ma - mi) % w == 0){
				// 縦方向の動く
				for (int k = mi; k <= ma; k += w){
					boardy[k / w][k % w] = true;
				}
			}else{
				// 横方向に動く
				for (int k = mi; k <= ma; ++k){
					boardx[k / w][k % w] = true;
				}
			}
		}
	}

	
	/*
	rep(i, h){
		rep(j, w){
			if(boardy[i][j])printf("o");
			else printf("x");
		}
		printf("\n");
	}

	printf("--\n");
	rep(i, h){
		rep(j, w){
			if(boardx[i][j])printf("o");
			else printf("x");
		}
		printf("\n");
	}
	*/
	rep(i, 1001)rep(j, 1001) memo[i][j] = -1;//初期化
	memo[0][0] = 0;
	queue<pair<int, int> > q;
	q.push(make_pair(0, 0));
	int cnt = 0;
	while(!q.empty() && cnt < 10000){
		cnt++;
		pair<int, int> now = q.front(); q.pop();
		// printf("first %d  second %d\n", now.first, now.second);
		for (int i = 0; i < 4; ++i){
			int nowy = now.first + dy[i], nowx = now.second + dx[i];
			if(0 <= nowy && nowy < h && 0 <= nowx && nowx < w){
				// printf("nowy %d nowx %d\n", nowy, nowx);
				if(memo[nowy][nowx] == -1){
					// printf("nowy %d nowx %d\n", nowy, nowx);
					if(i % 2 == 1 && boardy[nowy][nowx] == true){//縦の動き
						// printf("tateugoki nowy %d nowx %d\n", nowy, nowx);
						memo[nowy][nowx] = memo[now.first][now.second] + 1;
						q.push(make_pair(nowy, nowx));
						if(nowy == h - 1 && nowx == w - 1){
							printf("%d\n", memo[nowy][nowx]);
							return 0;
						}
					}else if(i % 2 == 0 && boardx[nowy][nowx]){//横の動き
						// printf("yokougoki nowy %d nowx %d\n", nowy, nowx);
						memo[nowy][nowx] = memo[now.first][now.second] + 1;
						q.push(make_pair(nowy, nowx));
						if(nowy == h - 1 && nowx == w - 1){
							printf("%d\n", memo[nowy][nowx]);
							return 0;
						}
					}
				}
			}
		}
	}
	printf("Odekakedekinai..\n");
	return 0;
}
0