結果

問題 No.2657 Falling Block Game
ユーザー kwm_tkwm_t
提出日時 2024-03-02 17:49:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 3,258 bytes
コンパイル時間 3,321 ms
コンパイル使用メモリ 258,544 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-03-02 17:49:12
合計ジャッジ時間 10,802 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 4 ms
6,676 KB
testcase_04 AC 33 ms
11,776 KB
testcase_05 AC 307 ms
9,732 KB
testcase_06 AC 195 ms
7,812 KB
testcase_07 AC 432 ms
9,732 KB
testcase_08 AC 233 ms
6,676 KB
testcase_09 AC 91 ms
11,904 KB
testcase_10 AC 213 ms
9,732 KB
testcase_11 AC 215 ms
9,732 KB
testcase_12 AC 217 ms
9,732 KB
testcase_13 AC 215 ms
9,732 KB
testcase_14 AC 219 ms
9,732 KB
testcase_15 AC 234 ms
9,732 KB
testcase_16 AC 214 ms
9,732 KB
testcase_17 AC 213 ms
9,732 KB
testcase_18 AC 214 ms
9,732 KB
testcase_19 AC 216 ms
9,732 KB
testcase_20 AC 118 ms
6,676 KB
testcase_21 AC 118 ms
6,676 KB
testcase_22 AC 118 ms
6,676 KB
testcase_23 AC 120 ms
6,676 KB
testcase_24 AC 120 ms
6,676 KB
testcase_25 AC 120 ms
6,676 KB
testcase_26 AC 118 ms
6,676 KB
testcase_27 AC 125 ms
6,676 KB
testcase_28 AC 117 ms
6,676 KB
testcase_29 AC 117 ms
6,676 KB
testcase_30 AC 86 ms
11,904 KB
testcase_31 AC 87 ms
11,904 KB
testcase_32 AC 86 ms
11,904 KB
testcase_33 AC 86 ms
11,904 KB
testcase_34 AC 86 ms
11,904 KB
testcase_35 AC 86 ms
11,904 KB
testcase_36 AC 86 ms
11,904 KB
testcase_37 AC 86 ms
11,904 KB
testcase_38 AC 86 ms
11,904 KB
testcase_39 AC 84 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint998244353;
//const int mod = 998244353;
//using mint = modint1000000007;
//const int mod = 1000000007;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
template<class S, S op(S l, S r), S e()>
struct DualSegtree {
private:
	int mn = 0;
	int mN = 0;
	int mlogN = 0;
	std::vector<S> A;
	void propagate(int i) {
		if (i >= mN) return;
		A[i * 2] = op(A[i * 2], A[i]);
		A[i * 2 + 1] = op(A[i * 2 + 1], A[i]);
		A[i] = e();
	}
	void full_propagate(int i) {
		for (int d = mlogN; d > 0; d--) propagate(i >> d);
	}
public:
	DualSegtree(int n = 0) {
		mn = n;
		mlogN = 0; mN = 1;
		while (mN < n) { mN *= 2; mlogN++; }
		A.assign(mN * 2, e());
	}
	void point_init(int p) {
		assert(0 <= p); assert(p < mn);
		p += mN;
		full_propagate(p);
		A[p] = e();
	}
	S get(int p) {
		assert(0 <= p); assert(p < mn);
		p += mN;
		full_propagate(p);
		return A[p];
	}
	void apply(int l, int r, S x) {
		l += mN;
		r += mN;
		if (l != mN) full_propagate(l - 1);
		if (r != mN * 2) full_propagate(r);
		while (l < r) {
			if (l & 1) { A[l] = op(A[l], x); l++; }
			if (r & 1) { r--; A[r] = op(A[r], x); }
			l /= 2; r /= 2;
		}
	}
};
//区間chmin、一点取得
using S = int;
S op(S x, S f) { return std::min(x, f); }
S e() { return { INF }; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<string>s(n);
	rep(i, n)cin >> s[i];
	reverse(all(s));
	vector dp(n, vector<int>(m, INF));
	rep(i, m)if ('#' != s[0][i])dp[0][i] = 0;
	rep2(i, 1, n) {
		vector<int>lwall(m), rwall(m);
		lwall[0] = -1;
		rep(j, m) {
			if ('#' == s[i][j])lwall[j] = j;
			else if (0 != j)lwall[j] = lwall[j - 1];
		}
		rwall[m - 1] = m;
		rrep(j, m) {
			if ('#' == s[i][j])rwall[j] = j;
			else if (j != m - 1)rwall[j] = rwall[j + 1];
		}
		DualSegtree<S, op, e>segl(m), segm(m), segr(m);
		rep(j, m) {
			if ('#' == s[i - 1][j])continue;
			if ('#' == s[i][j])continue;
			{
				int l = lwall[j] + 1;
				int r = max(lwall[j] + 1, j - dp[i - 1][j]);
				if (l <= r) segl.apply(l, r, j);
			}
			{
				int l = max(lwall[j] + 1, j - dp[i - 1][j]);
				int r = min(rwall[j], j + dp[i - 1][j] + 1);
				if (l <= r) segm.apply(l, r, dp[i - 1][j]);
			}
			{
				int l = min(rwall[j], j + dp[i - 1][j] + 1);
				int r = rwall[j];
				if (l <= r) segr.apply(l, r, -j);
			}
		}
		rep(j, m) {
			auto get = segl.get(j);
			if (INF != abs(get))chmin(dp[i][j], segl.get(j) - j);
			
			get = segm.get(j);
			if (INF != abs(get))chmin(dp[i][j], segm.get(j));
			
			get = segr.get(j);
			if (INF != abs(get))chmin(dp[i][j], segr.get(j) + j);
		}
	}
	rep(j, m)cout << dp.back()[j] << endl;
	return 0;
}
0