結果
| 問題 | No.2657 Falling Block Game |
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2024-03-01 22:13:04 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,410 bytes |
| 記録 | |
| コンパイル時間 | 2,853 ms |
| コンパイル使用メモリ | 270,328 KB |
| 実行使用メモリ | 12,000 KB |
| 最終ジャッジ日時 | 2024-09-29 14:12:49 |
| 合計ジャッジ時間 | 5,460 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
int h, w; cin >> h >> w;
vector<string> s(h);
for (string& s_i : s) cin >> s_i;
vector dp(h, vector(w, INF));
fill(dp.back().begin(), dp.back().end(), 0);
for (int i = h - 2; i >= 0; --i) {
REP(j, w) {
if (s[i][j] == '.') dp[i][j] = dp[i + 1][j];
}
vector<int> ord(w);
iota(ord.begin(), ord.end(), 0);
ranges::sort(ord, {}, [&](const int j) -> int { return dp[i][j]; });
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
for (const int j : ord) {
if (s[i][j] == '#') continue;
for (int d = 1; d <= dp[i + 1][j] && j - d >= 0; ++d) {
if (s[i][j - d] == '#' || !chmin(dp[i][j - d], dp[i + 1][j])) break;
}
if (j >= dp[i + 1][j] && dp[i][j - dp[i][j]] == dp[i + 1][j]) que.emplace(dp[i + 1][j], j - dp[i + 1][j]);
for (int d = 1; d <= dp[i + 1][j] && j + d < w; ++d) {
if (s[i][j + d] == '#' || !chmin(dp[i][j + d], dp[i + 1][j])) break;
}
if (j + dp[i + 1][j] < w && dp[i][j + dp[i + 1][j]] == dp[i + 1][j]) que.emplace(dp[i][j], j + dp[i + 1][j]);
}
while (!que.empty()) {
const auto [tmp, x] = que.top(); que.pop();
if (tmp > dp[i][x]) continue;
if (x > 0 && s[i][x - 1] == '.' && chmin(dp[i][x - 1], dp[i][x] + 1)) que.emplace(dp[i][x - 1], x - 1);
if (x + 1 < w && s[i][x + 1] == '.' && chmin(dp[i][x + 1], dp[i][x] + 1)) que.emplace(dp[i][x + 1], x + 1);
}
}
REP(j, w) cout << dp.front()[j] << '\n';
// REP(i, h) REP(j, w) cout << dp[i][j] << " \n"[j + 1 == w];
return 0;
}
emthrm