結果
問題 | No.340 雪の足跡 |
ユーザー | 👑 はまやんはまやん |
提出日時 | 2017-05-11 11:41:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 232 ms / 1,000 ms |
コード長 | 3,925 bytes |
コンパイル時間 | 3,311 ms |
コンパイル使用メモリ | 178,240 KB |
実行使用メモリ | 12,956 KB |
最終ジャッジ日時 | 2023-10-13 11:00:46 |
合計ジャッジ時間 | 8,027 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,724 KB |
testcase_01 | AC | 2 ms
7,688 KB |
testcase_02 | AC | 2 ms
7,732 KB |
testcase_03 | AC | 3 ms
7,664 KB |
testcase_04 | AC | 3 ms
7,636 KB |
testcase_05 | AC | 3 ms
7,644 KB |
testcase_06 | AC | 3 ms
7,656 KB |
testcase_07 | AC | 3 ms
7,648 KB |
testcase_08 | AC | 3 ms
7,648 KB |
testcase_09 | AC | 3 ms
7,632 KB |
testcase_10 | AC | 3 ms
7,748 KB |
testcase_11 | AC | 4 ms
7,812 KB |
testcase_12 | AC | 4 ms
7,812 KB |
testcase_13 | AC | 4 ms
8,000 KB |
testcase_14 | AC | 17 ms
8,748 KB |
testcase_15 | AC | 20 ms
11,064 KB |
testcase_16 | AC | 14 ms
8,456 KB |
testcase_17 | AC | 24 ms
10,928 KB |
testcase_18 | AC | 21 ms
10,944 KB |
testcase_19 | AC | 24 ms
11,016 KB |
testcase_20 | AC | 159 ms
12,592 KB |
testcase_21 | AC | 123 ms
10,540 KB |
testcase_22 | AC | 3 ms
7,640 KB |
testcase_23 | AC | 224 ms
12,696 KB |
testcase_24 | AC | 150 ms
12,612 KB |
testcase_25 | AC | 159 ms
12,624 KB |
testcase_26 | AC | 32 ms
8,640 KB |
testcase_27 | AC | 9 ms
7,740 KB |
testcase_28 | AC | 29 ms
8,676 KB |
testcase_29 | AC | 187 ms
12,488 KB |
testcase_30 | AC | 134 ms
12,112 KB |
testcase_31 | AC | 203 ms
12,200 KB |
testcase_32 | AC | 232 ms
12,796 KB |
testcase_33 | AC | 195 ms
12,832 KB |
testcase_34 | AC | 231 ms
12,956 KB |
testcase_35 | AC | 195 ms
12,728 KB |
testcase_36 | AC | 195 ms
12,844 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- #define INF INT_MAX/2 template<class T> struct SectionStructureOr { set<pair<T, T>> buf; SectionStructureOr() { buf.insert({ -INF, -INF }); buf.insert({ INF , INF }); } void add(T l, T r) { auto ite = buf.lower_bound({ l, -INF }); if (ite->first == INF) { ite--; if (ite->second <= l) buf.insert({ l, r }); else { T L = ite->first, R = ite->second; buf.erase(ite); buf.insert({ L, max(r, R) }); } } else { auto pre = buf.upper_bound({ r, -INF }); auto pp = pre; pp--; T L = min(l, ite->first), R = max(r, pp->second); buf.erase(ite, pre); buf.insert({ L, R }); }} auto get(T x) { auto ite = buf.lower_bound({ x, -INF }); if (ite->first == INF) return buf.end(); if (ite->second < x) return buf.end(); return ite; } auto end() { return buf.end(); } bool checkSameGroup(T a, T 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) cout << "[" << p.first << "," << p.second << "]\n"; } }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int W, H, N; int M[1010]; int B[1010][1010]; SectionStructureOr<int> vec[1010]; SectionStructureOr<int> 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].checkSameGroup(x, xx)) continue; } else { if (!vec[x].checkSameGroup(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; } //----------------------------------------------------------------- void _main() { cin >> W >> H >> N; rep(i, 0, N) { cin >> M[i]; rep(j, 0, M[i] + 1) cin >> B[i][j]; } makeEdge(); int ans = bfs(); if (0 <= ans) cout << ans << endl; else cout << "Odekakedekinai.." << endl; }