結果

問題 No.340 雪の足跡
ユーザー airisairis
提出日時 2016-01-30 15:33:30
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,813 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 89,176 KB
実行使用メモリ 15,516 KB
最終ジャッジ日時 2023-10-21 17:57:46
合計ジャッジ時間 7,358 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,500 KB
testcase_01 AC 4 ms
10,500 KB
testcase_02 AC 3 ms
8,472 KB
testcase_03 AC 4 ms
10,500 KB
testcase_04 AC 4 ms
10,504 KB
testcase_05 AC 4 ms
8,460 KB
testcase_06 AC 3 ms
10,500 KB
testcase_07 AC 4 ms
10,504 KB
testcase_08 AC 4 ms
10,504 KB
testcase_09 AC 4 ms
8,460 KB
testcase_10 AC 4 ms
10,504 KB
testcase_11 AC 6 ms
10,500 KB
testcase_12 AC 4 ms
10,504 KB
testcase_13 AC 5 ms
10,500 KB
testcase_14 AC 22 ms
14,596 KB
testcase_15 AC 27 ms
9,964 KB
testcase_16 AC 21 ms
9,076 KB
testcase_17 AC 33 ms
9,996 KB
testcase_18 AC 28 ms
10,020 KB
testcase_19 AC 36 ms
9,996 KB
testcase_20 AC 300 ms
15,496 KB
testcase_21 AC 196 ms
7,652 KB
testcase_22 AC 12 ms
15,500 KB
testcase_23 WA -
testcase_24 AC 286 ms
15,496 KB
testcase_25 AC 331 ms
15,504 KB
testcase_26 AC 53 ms
9,428 KB
testcase_27 AC 13 ms
7,676 KB
testcase_28 AC 45 ms
9,524 KB
testcase_29 AC 320 ms
15,292 KB
testcase_30 AC 222 ms
14,600 KB
testcase_31 AC 326 ms
15,216 KB
testcase_32 AC 375 ms
15,516 KB
testcase_33 AC 292 ms
15,516 KB
testcase_34 AC 380 ms
15,516 KB
testcase_35 AC 336 ms
15,516 KB
testcase_36 AC 338 ms
15,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <numeric>
#include <bitset>
#include <complex>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define foreach(itr, x) for (typeof((x).begin()) itr = (x).begin(); itr != (x).end(); itr++)
#define EPS (1e-14)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

const int INF = 1e+9 + 7;

int W, H, N, M;

int imos_v[1005][1005];
int imos_h[1005][1005];

queue<PII> Q;
int dist[1005][1005];

int di[] = {1,  -1};

void update(int y, int x, int ny, int nx, int imos[1005][1005]) {
	if (ny < 0 || ny >= H) return;
	if (nx < 0 || nx >= W) return;
	if (imos[y][x] <= 0 || imos[ny][nx] <= 0) return;
	if (dist[y][x] + 1 >= dist[ny][nx]) return;
	dist[ny][nx] = dist[y][x] + 1;
	Q.push(PII(ny, nx));
}

void bfs() {
	rep(i, 1005) rep(j, 1005) {
		dist[i][j] = INF;
	}
	dist[0][0] = 0;
	Q.push(PII(0, 0));
	while (!Q.empty()) {
		PII cur = Q.front(); Q.pop();
		int y = cur.first;
		int x = cur.second;
		for (int i = 0, ny = 0, nx = 0; i < 2; i++) {
			ny = y + di[i];
			nx = x;
			update(y, x, ny, nx, imos_v);

			ny = y;
			nx = x + di[i];
			update(y, x, ny, nx, imos_h);
		}
	}
}

void solve() {
	for (int i = 0; i <= H; i++) {
		for (int j = 0; j <= W; j++) {
			imos_h[i][j] += j-1>=0 ? imos_h[i][j-1] : 0;
			imos_v[i][j] += i-1>=0 ? imos_v[i-1][j] : 0;
		}
	}
#if 0
	rep(i, H + 1) rep(j, W + 1) {
		printf("%3d%c", imos_v[i][j], j == W ? '\n' : ' ');
	}
	printf("-----\n");
	rep(i, H + 1) rep(j, W + 1) {
		printf("%3d%c", imos_h[i][j], j == W ? '\n' : ' ');
	}
#endif
	bfs();

#if 0
	rep(i, H) rep(j, W) {
		printf("%3d%c", dist[i][j], j == W-1 ? '\n' : ' ');
	}
#endif

	if (dist[H-1][W-1] >= INF) {
		cout << "Odekakedekinai.." << endl;
	} else {
		cout << dist[H-1][W-1] << endl;
	}

}

PII toYX(int p) {
	int y = p / W;
	int x = p % W;
	return PII(y, x);
}

int main() {
	cin >> W >> H >> N;
	rep(i, N) {
		cin >> M;
		vector<int> B(M+1);
		rep(j, M+1) cin >> B[j];
		rep(j, M) {
			PII s = toYX(B[j]);
			PII e = toYX(B[j+1]);
			
			int sy = s.first;
			int sx = s.second;
			
			int ey = e.first;
			int ex = e.second;

			// printf("(%d,%d)->(%d,%d)\n", sx, sy, ex, ey);

			if (sx == ex) {
				// vertical
				int py = min(sy, ey);
				int qy = max(sy, ey);
				imos_v[py][sx] += 1;
				imos_v[qy+1][sx] -= 1;
			} else {
				// horizontal
				int px = min(sx, ex);
				int qx = max(sx, ex);
				imos_h[sy][px] += 1;
				imos_h[sy][qx+1] -= 1;
			}
		}
		// printf("=====\n");
	}
	solve();
	return 0;
}


0