結果

問題 No.340 雪の足跡
ユーザー antaanta
提出日時 2016-01-29 22:34:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 291 ms / 1,000 ms
コード長 2,666 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 92,172 KB
実行使用メモリ 11,912 KB
最終ジャッジ日時 2023-10-21 17:04:07
合計ジャッジ時間 5,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 12 ms
4,460 KB
testcase_15 AC 14 ms
4,504 KB
testcase_16 AC 10 ms
4,348 KB
testcase_17 AC 17 ms
4,604 KB
testcase_18 AC 14 ms
4,604 KB
testcase_19 AC 18 ms
4,604 KB
testcase_20 AC 139 ms
11,868 KB
testcase_21 AC 98 ms
4,348 KB
testcase_22 AC 11 ms
11,864 KB
testcase_23 AC 167 ms
11,864 KB
testcase_24 AC 127 ms
11,864 KB
testcase_25 AC 135 ms
11,868 KB
testcase_26 AC 24 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 226 ms
8,584 KB
testcase_30 AC 144 ms
7,448 KB
testcase_31 AC 249 ms
11,216 KB
testcase_32 AC 291 ms
11,912 KB
testcase_33 AC 226 ms
11,912 KB
testcase_34 AC 289 ms
11,912 KB
testcase_35 AC 172 ms
11,912 KB
testcase_36 AC 175 ms
11,912 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |                         scanf("%d", &M);
      |                         ~~~~~^~~~~~~~~~
main.cpp:48:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |                                 scanf("%d", &B);
      |                                 ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int W; int H; int N;
	while(~scanf("%d%d%d", &W, &H, &N)) {
		vector<vi> vert(H, vi(W)), hori(H, vi(W));
		rep(ii, N) {
			int M;
			scanf("%d", &M);
			int prevB = -1;
			for(int i = 0; i < M + 1; ++ i) {
				int B;
				scanf("%d", &B);
				if(prevB != -1) {
					if(prevB / W == B / W) {
						pii p = minmax(prevB % W, B % W);
						++ hori[B / W][p.first];
						-- hori[B / W][p.second];
					} else {
						pii p = minmax(prevB / W, B / W);
						++ vert[p.first][B % W];
						-- vert[p.second][B % W];
					}
				}
				prevB = B;
			}
		}
		rep(i, H) rep(j, W - 1)
			hori[i][j + 1] += hori[i][j];
		rep(j, W) rep(i, H - 1)
			vert[i + 1][j] += vert[i][j];
		vector<bool> vis(H * W);
		vi q, nq;
		nq.push_back(0);
		int ans = INF, d = 0;
		while(!nq.empty()) {
			q.swap(nq);
			while(!q.empty()) {
				int i = q.back(); q.pop_back();
				if(vis[i]) continue;
				vis[i] = true;
				if(i == H * W - 1) {
					ans = d;
					nq.clear();
					break;
				}
				int y = i / W, x = i % W;
				static const int dy[4] = { 0, 1, 0, -1 }, dx[4] = { 1, 0, -1, 0 };
				for(int d = 0; d < 4; ++ d) {
					int yy = y + dy[d], xx = x + dx[d];
					if(yy < 0 || yy >= H || xx < 0 || xx >= W) continue;
					if(dy[d] != 0) {
						if(vert[min(y, yy)][x] == 0) continue;
					} else {
						if(hori[yy][min(x, xx)] == 0) continue;
					}
					nq.push_back(yy * W + xx);
				}
			}
			++ d;
		}
		if(ans == INF)
			puts("Odekakedekinai..");
		else
			printf("%d\n", ans);
	}
	return 0;
}
0