結果
問題 | No.340 雪の足跡 |
ユーザー |
![]() |
提出日時 | 2016-04-07 01:07:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 459 ms / 1,000 ms |
コード長 | 2,440 bytes |
コンパイル時間 | 700 ms |
コンパイル使用メモリ | 90,932 KB |
実行使用メモリ | 23,168 KB |
最終ジャッジ日時 | 2024-10-04 02:24:54 |
合計ジャッジ時間 | 7,180 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 32 |
ソースコード
/* -*- 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 */int nbrs[MAX_H][MAX_W][4], 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);if (x0 < x1)nbrs[y0][x0][0]++, nbrs[y0][x1][0]--;else if (y0 < y1)nbrs[y0][x0][1]++, nbrs[y1][x0][1]--;else if (x0 > x1)nbrs[y0][x1][0]++, nbrs[y0][x0][0]--;elsenbrs[y1][x0][1]++, nbrs[y0][x0][1]--;x0 = x1, y0 = y1;}}for (int y = 0; y < h; y++)for (int x = 1; x < w; x++) nbrs[y][x][0] += nbrs[y][x - 1][0];for (int x = 0; x < w; x++)for (int y = 1; y < h; y++) nbrs[y][x][1] += nbrs[y - 1][x][1];for (int y = 0; y < h; y++)for (int x = 0; x < w; x++) {if (nbrs[y][x][0]) nbrs[y][x + 1][2] = true;if (nbrs[y][x][1]) nbrs[y + 1][x][3] = true;}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..");elseprintf("%d\n", gd);return 0;}