結果
| 問題 |
No.340 雪の足跡
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2016-04-07 00:06:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,179 bytes |
| コンパイル時間 | 830 ms |
| コンパイル使用メモリ | 90,064 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-10-04 02:24:27 |
| 合計ジャッジ時間 | 19,837 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 23 TLE * 9 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 340.cc: No.340 雪の足跡 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_W = 1000;
const int MAX_H = 1000;
const int dxs[] = {1, 0, -1, 0}, dys[] = {0, 1, 0, -1};
const int INF = 1 << 30;
/* typedef */
typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
/* global variables */
bool nbrs[MAX_H][MAX_W][4];
int dists[MAX_H][MAX_W];
/* subroutines */
/* main */
int main() {
int w, h, n;
cin >> w >> h >> n;
while (n--) {
int m, b0;
cin >> m >> b0;
int x0 = b0 % w, y0 = b0 / w;
while (m--) {
int b1;
cin >> b1;
int x1 = b1 % w, y1 = b1 / w;
//printf("(%d,%d)->(%d,%d)\n", x0, y0, x1, y1);
int di = (x1 > x0) ? 0 : (y1 > y0) ? 1 : (x1 < x0) ? 2 : 3;
for (int px = x0, py = y0; px != x1 || py != y1;) {
int qx = px + dxs[di], qy = py + dys[di];
nbrs[py][px][di] = nbrs[qy][qx][(di + 2) & 3] = true;
//printf("nbrs[%d][%d][%d]=nbrs[%d][%d][%d]=true\n",
//py, px, di, qy, qx, (di + 2) & 3);
px = qx, py = qy;
}
x0 = x1, y0 = y1;
}
}
for (int y = 0; y < h; y++)
for (int x = 0; x < w; x++) dists[y][x] = INF;
dists[0][0] = 0;
queue<pii> q;
q.push(pii(0, 0));
while (! q.empty()) {
pii u = q.front(); q.pop();
int ux = u.first, uy = u.second;
//printf("x=%d,y=%d,d=%d\n", ux, uy, dists[uy][ux]);
if (ux == w - 1 && uy == h - 1) break;
int vd = dists[uy][ux] + 1;
for (int di = 0; di < 4; di++)
if (nbrs[uy][ux][di]) {
int vx = ux + dxs[di], vy = uy + dys[di];
//printf(" (%d,%d)[%d]->(%d,%d):%d\n", ux, uy, di, vx, vy, dists[vy][vx]);
if (dists[vy][vx] > vd) {
dists[vy][vx] = vd;
q.push(pii(vx, vy));
}
}
}
int gd = dists[h - 1][w - 1];
if (gd >= INF)
puts("Odekakedekinai..");
else
printf("%d\n", gd);
return 0;
}
tnakao0123