結果

問題 No.2412 YOU Grow Bigger!
ユーザー kabipoyokabipoyo
提出日時 2023-08-11 22:23:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,550 bytes
コンパイル時間 5,426 ms
コンパイル使用メモリ 288,252 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2023-08-11 22:23:28
合計ジャッジ時間 6,981 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,384 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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_back
using 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;
		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;
		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;
			G[x].pb({max(abs(a-c)/3, abs(z-b)/3), y});
		}
	}

	vi dist;
	dijkstra(m[{-1, W+1}], dist);
	std::cout << dist[m[{H+1, -1}]] << '\n';
}
0