結果

問題 No.340 雪の足跡
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-05-27 19:24:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,854 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 85,196 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-16 17:47:01
合計ジャッジ時間 6,884 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,520 KB
testcase_01 WA -
testcase_02 AC 7 ms
11,392 KB
testcase_03 WA -
testcase_04 AC 7 ms
11,264 KB
testcase_05 WA -
testcase_06 AC 7 ms
11,392 KB
testcase_07 AC 7 ms
11,392 KB
testcase_08 AC 7 ms
11,264 KB
testcase_09 AC 7 ms
11,520 KB
testcase_10 WA -
testcase_11 AC 9 ms
11,392 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 23 ms
11,520 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 8 ms
11,392 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 302 ms
11,392 KB
testcase_26 AC 54 ms
11,520 KB
testcase_27 AC 15 ms
11,520 KB
testcase_28 AC 46 ms
11,520 KB
testcase_29 AC 360 ms
11,648 KB
testcase_30 AC 242 ms
11,392 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 290 ms
11,520 KB
testcase_36 AC 292 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for (int i=(n)-1;i>=0;i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define REPS(i,f,n) for (int i=(f)-1;i>=(n);i--)
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};


int main(void){
	int w, h, n;
	cin >> w >> h >> n;

	int board[1001][1001];
	rep(i, h){
		rep(j, w)
			board[i][j] = 0;
	}

	//大人が通った場所を1に
	int m;
	rep(i, n){
		cin >> m;
		rep(i, m + 1){
			int num;
			cin >> num;
			int dy_tmp = num / w;
			int dx_tmp = num % w;

			board[dy_tmp][dx_tmp] = 1;
		}
	}

	//子供がどこを通るかを確かめる
	queue<pint> q;//現在の位置を入れていく
	q.push(mp(0, 0));
	int cnt = 0;
	
	int record[1010][1010];
	rep(i, h){
		rep(j, w)
			record[i][j] = 0;
	}

	while(!q.empty()){
		pint tmp = q.front(); //tmp(y, x)情報
		q.pop();

		rep(i, 4){
			int dy_board = tmp.fi + dy[i];
			int dx_board = tmp.se + dx[i];

			if (0 <= dx_board && dx_board <= w - 1 && 0 <= dy_board && dy_board <= h - 1 && board[tmp.fi][tmp.se] != 0){
				if (board[dy_board][dx_board] == 1 && record[dy_board][dx_board] == 0){
					record[dy_board][dx_board] = record[tmp.fi][tmp.se] + 1;
					q.push(mp(dy_board, dx_board));
				}
			}

			if (dy_board == h - 1 && dx_board == w - 1){
				printf("%d\n", record[h - 1][w - 1]);
				return 0;
			}
		}
	}

	printf("Odekakedekinai..\n");

	return 0;
}
0