結果

問題 No.340 雪の足跡
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-08-09 13:44:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,702 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 80,184 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-04-24 22:58:35
合計ジャッジ時間 17,884 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,808 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 WA -
testcase_05 RE -
testcase_06 AC 5 ms
7,552 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 5 ms
7,552 KB
testcase_10 WA -
testcase_11 AC 7 ms
7,680 KB
testcase_12 AC 5 ms
7,552 KB
testcase_13 AC 7 ms
7,680 KB
testcase_14 AC 29 ms
8,320 KB
testcase_15 AC 36 ms
8,448 KB
testcase_16 AC 27 ms
8,064 KB
testcase_17 AC 50 ms
8,448 KB
testcase_18 AC 39 ms
8,320 KB
testcase_19 AC 47 ms
8,704 KB
testcase_20 TLE -
testcase_21 TLE -
testcase_22 RE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 68 ms
8,576 KB
testcase_27 AC 16 ms
7,936 KB
testcase_28 AC 63 ms
8,576 KB
testcase_29 AC 626 ms
12,288 KB
testcase_30 AC 409 ms
11,520 KB
testcase_31 AC 672 ms
11,904 KB
testcase_32 AC 809 ms
12,672 KB
testcase_33 AC 607 ms
12,544 KB
testcase_34 AC 809 ms
12,544 KB
testcase_35 TLE -
testcase_36 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
vector<int> b[1001];
bool board[1001][1001];
int memo[1001][1001];
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){
			if((b[i][j + 1] - b[i][j]) % w == 0){
				// 縦方向の動く
				for (int k = b[i][j]; k <= b[i][j + 1]; k += w){
					// printf("tate %d %d\n", k / w, k % w);
					board[k / w][k % w] = true;
				}
			}else{
				// 横方向に動く
				for (int k = b[i][j]; k <= b[i][j + 1]; ++k){
					// printf("yoko %d %d\n", k / w, k % w);
					board[k / w][k % w] = true;
				}
			}
		}
	}

	/*
	rep(i, h){
		rep(j, w){
			if(board[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 < 100000){
		cnt++;
		auto now = q.front(); q.pop();

		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){
				if(memo[nowy][nowx] == -1 && board[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