結果
| 問題 |
No.2657 Falling Block Game
|
| コンテスト | |
| ユーザー |
sotanishy
|
| 提出日時 | 2024-03-01 22:12:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 173 ms / 2,000 ms |
| コード長 | 2,315 bytes |
| コンパイル時間 | 3,078 ms |
| コンパイル使用メモリ | 259,556 KB |
| 実行使用メモリ | 12,124 KB |
| 最終ジャッジ日時 | 2024-09-29 14:10:09 |
| 合計ジャッジ時間 | 7,276 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
return a > b ? (a = b, 1) : 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int H, W;
cin >> H >> W;
vector<string> S(H);
for (auto& row : S) cin >> row;
vector<int> dp(W, 0);
const int INF = 1e9;
revrep(i, H, 0) {
vector<int> ndp(W, INF);
vector<vector<int>> diff(W);
multiset<int> st;
int left = -1;
int reset = -1;
rep(j, 0, W) {
if (S[i][j] == '#') {
st.clear();
left = -1;
reset = j;
continue;
}
st.insert(dp[j]);
if (j + dp[j] < W) {
diff[j + dp[j]].push_back(j);
}
if (!st.empty()) {
chmin(ndp[j], *st.begin());
}
if (left != -1) {
chmin(ndp[j], j - left);
}
for (int k : diff[j]) {
if (k <= reset) continue;
st.erase(st.find(dp[k]));
chmax(left, k);
}
diff[j].clear();
}
st.clear();
int right = W;
reset = W;
revrep(j, W, 0) {
if (S[i][j] == '#') {
st.clear();
right = W;
reset = j;
continue;
}
st.insert(dp[j]);
if (j - dp[j] >= 0) {
diff[j - dp[j]].push_back(j);
}
if (!st.empty()) {
chmin(ndp[j], *st.begin());
}
if (right != W) {
chmin(ndp[j], right - j);
}
for (int k : diff[j]) {
if (reset <= k) continue;
st.erase(st.find(dp[k]));
chmin(right, k);
}
}
dp.swap(ndp);
}
rep(j, 0, W) cout << dp[j] << "\n";
}
sotanishy