結果
問題 | No.2657 Falling Block Game |
ユーザー |
![]() |
提出日時 | 2024-03-01 22:54:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,099 ms / 2,000 ms |
コード長 | 3,695 bytes |
コンパイル時間 | 1,151 ms |
コンパイル使用メモリ | 99,960 KB |
最終ジャッジ日時 | 2025-02-19 22:55:54 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
main.cpp: In member function ‘int segtree::query(int, int)’: main.cpp:34:21: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘1.0e+10’ to ‘2147483647’ [-Woverflow] 34 | int score = 1e10; | ^~~~
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <string>#include <cmath>using namespace std;class segtree {private:int size;vector<int> dat;public:segtree(int n) {size = 1;while (size < n) {size *= 2;}dat.assign(size * 2, 0);}void update(int x, int a) {x += size;dat[x] = a;while (x > 1) {x /= 2;dat[x] = min(dat[2 * x], dat[2 * x + 1]);}}int query(int u, int v) {u += size;v += size;int score = 1e10;while (u < v) {if (u & 1) {score = min(score, dat[u]);u++;}if (v & 1) {v--;score = min(score, dat[v]);}u /= 2;v /= 2;}return score;}};class segtreemax {private:int size;vector<int> dat;public:segtreemax(int n) {size = 1;while (size < n) {size *= 2;}dat.assign(size * 2, 0);}void update(int x, int a) {x += size;dat[x] = a;while (x > 1) {x /= 2;dat[x] = max(dat[2 * x], dat[2 * x + 1]);}}int query(int u, int v) {u += size;v += size;int score = 0;while (u < v) {if (u & 1) {score = max(score, dat[u]);u++;}if (v & 1) {v--;score = max(score, dat[v]);}u /= 2;v /= 2;}return score;}};int main() {int H, W;cin >> H >> W;vector<string> A(H);for (int i = 0; i < H; ++i) {cin >> A[i];}vector<int> dp(W, 0);segtree Z(W);for (int i = H - 2; i >= 0; --i) {vector<int> dp2(W, 1e8);vector<int> L;L.push_back(-1);for (int j = 0; j < W; ++j) {if (A[i][j] == '#') {L.push_back(j);}}L.push_back(W);for (int j = 0; j < W; ++j) {if (A[i][j] == '#') {continue;}int pos = lower_bound(L.begin(), L.end(), j) - L.begin();int a = L[pos - 1];int b = L[pos];int ans = 1e8;int l = 0, r = W - 1;while (true) {if (l == r) {break;}int m = (l + r) / 2;int y = j + m;if (y >= b) {y = b - 1;}int score = Z.query(j, y + 1);if (score <= m) {r = m;} else {l = m + 1;}}ans = min(ans, l);l = 0;r = W - 1;while (true) {if (l == r) {break;}int m = (l + r) / 2;int y = j - m;if (y <= a) {y = a + 1;}int score = Z.query(y, j + 1);if (score <= m) {r = m;} else {l = m + 1;}}ans = min(ans, l);dp2[j] = ans;}dp = dp2;for (int j = 0; j < W; ++j) {Z.update(j, dp[j]);}}for (int i = 0; i < W; ++i) {cout << dp[i] << endl;}return 0;}