結果

問題 No.2657 Falling Block Game
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-03-02 06:51:25
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 555 ms / 2,000 ms
コード長 3,091 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 121,856 KB
実行使用メモリ 61,816 KB
最終ジャッジ日時 2024-03-02 06:51:39
合計ジャッジ時間 13,591 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 201 ms
36,600 KB
testcase_05 AC 106 ms
15,288 KB
testcase_06 AC 108 ms
23,440 KB
testcase_07 AC 231 ms
19,968 KB
testcase_08 AC 241 ms
11,252 KB
testcase_09 AC 555 ms
60,024 KB
testcase_10 AC 55 ms
11,876 KB
testcase_11 AC 56 ms
11,748 KB
testcase_12 AC 55 ms
11,748 KB
testcase_13 AC 54 ms
11,748 KB
testcase_14 AC 55 ms
11,876 KB
testcase_15 AC 55 ms
11,748 KB
testcase_16 AC 55 ms
11,748 KB
testcase_17 AC 54 ms
11,748 KB
testcase_18 AC 54 ms
11,748 KB
testcase_19 AC 55 ms
11,748 KB
testcase_20 AC 166 ms
31,500 KB
testcase_21 AC 163 ms
31,004 KB
testcase_22 AC 171 ms
32,248 KB
testcase_23 AC 171 ms
32,596 KB
testcase_24 AC 171 ms
32,408 KB
testcase_25 AC 170 ms
32,312 KB
testcase_26 AC 174 ms
32,552 KB
testcase_27 AC 170 ms
31,668 KB
testcase_28 AC 168 ms
31,780 KB
testcase_29 AC 170 ms
31,696 KB
testcase_30 AC 489 ms
61,688 KB
testcase_31 AC 474 ms
61,688 KB
testcase_32 AC 474 ms
61,816 KB
testcase_33 AC 476 ms
61,688 KB
testcase_34 AC 479 ms
61,688 KB
testcase_35 AC 490 ms
61,688 KB
testcase_36 AC 472 ms
61,816 KB
testcase_37 AC 466 ms
61,432 KB
testcase_38 AC 477 ms
61,688 KB
testcase_39 AC 447 ms
60,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }

string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


class MinPQue(T) {
  BinaryHeap!(Array!T, "a > b") que0, que1;
  int size() { return cast(int)(que0.length) - cast(int)(que1.length); }
  void push(T t) { que0.insert(t); }
  void erase(T t) { que1.insert(t); }
  void reduce() { for (; que0.length && que1.length && que0.front == que1.front; que0.removeFront, que1.removeFront) {} }
  T top() { reduce; return que0.front; }
  void pop() { reduce; que0.front; }
}

enum INF = 1001001001;

void main() {
  try {
    for (; ; ) {
      const M = readInt;
      const N = readInt;
      auto S = new string[](M, N);
      foreach (x; 0 .. M) {
        S[x] = readToken;
      }
      
      auto addss = new int[][N + 1];
      auto remss = new int[][N + 1];
      
      auto dp = new int[N];
      foreach_reverse (x; 0 .. M - 1) {
        for (int y0 = 0, y1; y0 < N; y0 = y1) {
          for (y1 = y0; y1 < N && S[x][y0] == S[x][y1]; ++y1) {}
          if (S[x][y0] == '.') {
            foreach (y; y0 .. y1 + 1) {
              addss[y] = [];
              remss[y] = [];
            }
            foreach (y; y0 .. y1) if (dp[y] < INF) {
              // free
              const yL = max(y0, y - dp[y]);
              const yR = min(y1, y + dp[y] + 1);
              addss[yL] ~= dp[y];
              remss[yR] ~= dp[y];
            }
            auto que = new MinPQue!int;
            foreach (y; y0 .. y1) {
              foreach (f; addss[y]) que.push(f);
              foreach (f; remss[y]) que.erase(f);
              dp[y] = que.size ? que.top : INF;
            }
            foreach (y; y0 .. y1 - 1) chmin(dp[y + 1], dp[y] + 1);
            foreach_reverse (y; y0 + 1 .. y1) chmin(dp[y - 1], dp[y] + 1);
          } else {
            dp[y0 .. y1] = INF;
          }
        }
        debug {
          writeln(dp);
        }
      }
      
      foreach (y; 0 .. N) {
        writeln(dp[y]);
      }
    }
  } catch (EOFException e) {
  }
}
0