結果
問題 | No.2412 YOU Grow Bigger! |
ユーザー |
![]() |
提出日時 | 2023-08-11 22:56:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,104 bytes |
コンパイル時間 | 4,536 ms |
コンパイル使用メモリ | 279,648 KB |
最終ジャッジ日時 | 2025-02-16 01:58:38 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 WA * 9 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;typedef int64_t lint;#define rep(i, n) for(int i=0; i<n; i++)#define repx(i, l, n) for(int i=l; i<n; i++)#define all(v) v.begin(), v.end()#define show(x) cout << #x << ": " << x << endl;#define list(x) cout << #x << ": " << x << " ";#define pb push_backusing vi = vector<lint>;using vvi = vector<vector<lint>>;template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }template<class T> inline void drop(T x) { cout << x << endl; exit(0); }template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }constexpr lint LINF = LLONG_MAX/2;using pint = pair<lint, lint>;using vp = vector<pint>;template<class T> map<T, int> coord_comp(set<T> s) {int a = 0;map<T, int> m;for (auto u : s) m[u] = ++a;return m;}template<class T> inline void vvout(vector<T> v) {rep(i, v.size()) { rep(j, v[i].size()) { list(v[i][j].first) list(v[i][j].second) } cout << endl; }}vector<vector<pint>> G;void dijkstra(lint start, vector<lint> &dist) {lint a=0, b=0, x, y, N = G.size();dist.resize(N, LINF); dist[start] = 0;priority_queue<pint, vector<pint>, greater<pint>> PQ;PQ.push(make_pair(0, start));while (!PQ.empty()) {tie(x, a) = PQ.top(); PQ.pop();if (dist[a] < x) continue;for (auto p : G[a]) {tie(y, b) = p;if (chmin(dist[b], x+y)) PQ.push(make_pair(x+y, b));}}}int main() {lint H, W;cin >> H >> W;std::vector<string> v(H);vin(v);lint a=0, b=0, c=0, x, y, z;set<pint> s;s.insert({-1, W+1});s.insert({H+1, -1});rep(i, H) {rep(j, W) {if (v[i][j] == '#') s.insert({i, j});}}map<pint, int> m = coord_comp(s);G.resize(m.size()+1);x = m[{-1, W+1}];for (auto p : s) {if (x == m[p]) continue;tie(c, z) = p;if (c >= H-3 && z < 3) continue;if (c >= H-3) G[x].pb({c/3, m[p]});else if (z < 3) G[x].pb({(W-z-1)/3, m[p]});else G[x].pb({min(c/3, (W-z-1)/3), m[p]});}x = m[{H+1, -1}];for (auto p : s) {if (x == m[p]) continue;tie(c, z) = p;if (c < 3 && z >= W-3) continue;if (c < 3) G[m[p]].pb({(H-c-1)/3, x});else if (z >= W-3) G[m[p]].pb({z/3, x});else G[m[p]].pb({min((H-c-1)/3, z/3), x});}for (auto p : s) {x = m[p];tie(c, z) = p;if (c == -1 || z == -1) continue;for (auto q : s) {y = m[q];if (x == y) continue;tie(a, b) = q;if (a == -1 || b == -1) continue;if (max(abs(a-c), abs(z-b)) >= 6) {if (min(abs(a-c), abs(z-b)) >= 5) G[x].pb({2, y});else G[x].pb({1, y});} else if (max(abs(a-c), abs(z-b)) >= 4) {G[x].pb({1, y});} else if (max(abs(a-c), abs(z-b)) >= 3) {if (min(abs(a-c), abs(z-b)) >= 3) G[x].pb({1, y});else G[x].pb({0, y});} else {G[x].pb({0, y});}}}vi dist;dijkstra(m[{-1, W+1}], dist);std::cout << dist[m[{H+1, -1}]] << '\n';}