結果

問題 No.2657 Falling Block Game
ユーザー 👑 emthrmemthrm
提出日時 2024-03-01 22:26:29
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 2,439 bytes
コンパイル時間 3,213 ms
コンパイル使用メモリ 266,964 KB
実行使用メモリ 19,320 KB
最終ジャッジ日時 2024-03-01 22:26:42
合計ジャッジ時間 8,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 39 ms
11,904 KB
testcase_05 AC 166 ms
18,352 KB
testcase_06 AC 124 ms
11,416 KB
testcase_07 AC 127 ms
19,320 KB
testcase_08 AC 113 ms
6,676 KB
testcase_09 AC 106 ms
11,904 KB
testcase_10 AC 89 ms
16,728 KB
testcase_11 AC 88 ms
16,836 KB
testcase_12 AC 87 ms
16,844 KB
testcase_13 AC 88 ms
16,836 KB
testcase_14 AC 88 ms
16,848 KB
testcase_15 AC 88 ms
16,836 KB
testcase_16 AC 87 ms
16,844 KB
testcase_17 AC 92 ms
16,836 KB
testcase_18 AC 88 ms
16,836 KB
testcase_19 AC 89 ms
16,840 KB
testcase_20 AC 114 ms
6,676 KB
testcase_21 AC 114 ms
6,676 KB
testcase_22 AC 116 ms
6,676 KB
testcase_23 AC 116 ms
6,676 KB
testcase_24 AC 115 ms
6,676 KB
testcase_25 AC 116 ms
6,676 KB
testcase_26 AC 115 ms
6,676 KB
testcase_27 AC 116 ms
6,676 KB
testcase_28 AC 115 ms
6,676 KB
testcase_29 AC 113 ms
6,676 KB
testcase_30 AC 108 ms
11,904 KB
testcase_31 AC 105 ms
11,904 KB
testcase_32 AC 106 ms
11,904 KB
testcase_33 AC 106 ms
11,904 KB
testcase_34 AC 105 ms
11,904 KB
testcase_35 AC 107 ms
11,904 KB
testcase_36 AC 109 ms
11,904 KB
testcase_37 AC 107 ms
11,904 KB
testcase_38 AC 106 ms
11,904 KB
testcase_39 AC 107 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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) {
    vector<int> l(w, w), r(w, -1);
    for (int j = 0, cur = -1; j < w; ++j) {
      if (s[i][j] == '#') {
        cur = j;
      } else {
        l[j] = cur + 1;
      }
    }
    for (int j = w - 1, cur = w; j >= 0; --j) {
      if (s[i][j] == '#') {
        cur = j;
      } else {
        r[j] = cur - 1;
      }
    }
    vector<vector<int>> ins(w), era(w);
    REP(j, w) {
      if (s[i][j] == '.') {
        ins[max(j - dp[i + 1][j], l[j])].emplace_back(dp[i + 1][j]);
        era[min(j + dp[i + 1][j], r[j])].emplace_back(dp[i + 1][j]);
      }
    }
    multiset<int> st;
    REP(j, w) {
      for (const int x : ins[j]) st.emplace(x);
      if (s[i][j] == '.') dp[i][j] = *st.begin();
      for (const int x : era[j]) st.erase(st.find(x));
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
    REP(j, w) {
      if (s[i][j] == '.') que.emplace(dp[i][j], 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;
}
0