結果
問題 | No.340 雪の足跡 |
ユーザー |
👑 ![]() |
提出日時 | 2017-02-26 18:43:37 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 255 ms / 1,000 ms |
コード長 | 2,814 bytes |
コンパイル時間 | 1,809 ms |
コンパイル使用メモリ | 177,420 KB |
実行使用メモリ | 13,004 KB |
最終ジャッジ日時 | 2023-09-02 10:05:53 |
合計ジャッジ時間 | 6,831 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,776 KB |
testcase_01 | AC | 2 ms
7,736 KB |
testcase_02 | AC | 3 ms
7,704 KB |
testcase_03 | AC | 3 ms
7,696 KB |
testcase_04 | AC | 3 ms
7,924 KB |
testcase_05 | AC | 3 ms
7,964 KB |
testcase_06 | AC | 3 ms
7,736 KB |
testcase_07 | AC | 3 ms
7,728 KB |
testcase_08 | AC | 3 ms
7,712 KB |
testcase_09 | AC | 2 ms
7,724 KB |
testcase_10 | AC | 3 ms
7,856 KB |
testcase_11 | AC | 5 ms
7,896 KB |
testcase_12 | AC | 3 ms
7,880 KB |
testcase_13 | AC | 4 ms
8,196 KB |
testcase_14 | AC | 18 ms
8,816 KB |
testcase_15 | AC | 22 ms
10,980 KB |
testcase_16 | AC | 16 ms
8,476 KB |
testcase_17 | AC | 27 ms
11,084 KB |
testcase_18 | AC | 23 ms
11,060 KB |
testcase_19 | AC | 27 ms
11,064 KB |
testcase_20 | AC | 180 ms
12,660 KB |
testcase_21 | AC | 141 ms
10,592 KB |
testcase_22 | AC | 3 ms
7,728 KB |
testcase_23 | AC | 243 ms
12,788 KB |
testcase_24 | AC | 168 ms
12,828 KB |
testcase_25 | AC | 178 ms
12,632 KB |
testcase_26 | AC | 35 ms
8,640 KB |
testcase_27 | AC | 10 ms
7,748 KB |
testcase_28 | AC | 31 ms
8,820 KB |
testcase_29 | AC | 206 ms
12,596 KB |
testcase_30 | AC | 147 ms
12,084 KB |
testcase_31 | AC | 222 ms
12,320 KB |
testcase_32 | AC | 254 ms
12,836 KB |
testcase_33 | AC | 210 ms
12,872 KB |
testcase_34 | AC | 255 ms
13,004 KB |
testcase_35 | AC | 215 ms
12,900 KB |
testcase_36 | AC | 215 ms
12,864 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<b;i++) #define INF INT_MAX/2 struct SectionStructure { set<pair<int, int>> buf; SectionStructure() { buf.insert({ -INF, -INF }); buf.insert({ INF , INF }); } void add(int l, int r) { auto ite = buf.lower_bound({ l, -INF }); if (ite->first == INF) { // 大きいやつが無い ite--; if (ite->second <= l) { // 被ってないなら追加 buf.insert({ l, r }); } else { // 被ってるならそれとくっつける int L = ite->first; int R = ite->second; buf.erase(ite); buf.insert({ L, max(r, R) }); } } else { // 被ってるのがある auto pre = buf.upper_bound({ r, -INF }); auto pp = pre; pp--; int L = min(l, ite->first); int R = max(r, pp->second); buf.erase(ite, pre); buf.insert({ L, R }); } } bool check(int a, int b) { if (a > b) swap(a, b); auto aa = buf.upper_bound({ a, INF }); aa--; if (aa->first == -INF) return false; return b <= aa->second; } void print() { printf("<>\n"); for (auto p : buf) printf("[%d,%d]\n", p.first, p.second); } }; //----------------------------------------------------------------- int W, H, N; int M[1010]; int B[1010][1010]; SectionStructure vec[1010]; SectionStructure hor[1010]; //----------------------------------------------------------------- void makeEdge() { rep(i, 0, N) { rep(j, 0, M[i]) { int a = B[i][j]; int b = B[i][j + 1]; if (a > b) swap(a, b); int ya = a / W; int xa = a % W; int yb = b / W; int xb = b % W; if (ya == yb) { // x軸での移動 hor[ya].add(xa, xb); } else { // y軸での移動 vec[xa].add(ya, yb); } } } } //----------------------------------------------------------------- bool done[1010][1010]; int dist[1010][1010]; int dx[4] = { 0, 1, 0, -1 }; int dy[4] = { -1, 0, 1, 0 }; int bfs() { queue<int> que; done[0][0] = true; dist[0][0] = 0; que.push(0); while (!que.empty()) { int y = que.front() / 1010; int x = que.front() % 1010; que.pop(); if (y == H - 1 && x == W - 1) return dist[y][x]; rep(i, 0, 4) { int xx = x + dx[i]; int yy = y + dy[i]; if (xx < 0 || W <= xx) continue; if (yy < 0 || H <= yy) continue; if (i % 2 == 1) { if (!hor[y].check(x, xx)) continue; } else { if (!vec[x].check(y, yy)) continue; } if (done[yy][xx]) continue; done[yy][xx] = 1; dist[yy][xx] = dist[y][x] + 1; que.push(yy * 1010 + xx); } } return -1; } //----------------------------------------------------------------- int main() { cin >> W >> H >> N; rep(i, 0, N) { scanf("%d", &M[i]); rep(j, 0, M[i] + 1) scanf("%d", &B[i][j]); } makeEdge(); int ans = bfs(); if (0 <= ans) cout << ans << endl; else cout << "Odekakedekinai.." << endl; }