結果
| 問題 |
No.2657 Falling Block Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-01 23:10:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 339 ms / 2,000 ms |
| コード長 | 3,609 bytes |
| コンパイル時間 | 2,194 ms |
| コンパイル使用メモリ | 189,676 KB |
| 実行使用メモリ | 15,064 KB |
| 最終ジャッジ日時 | 2024-09-29 14:56:24 |
| 合計ジャッジ時間 | 7,441 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;
void solve(){
int h, w; cin >> h >> w;
vector<vector<char>> s(h, vector<char>(w));
for(int i=0; i<h; i++)for(int j=0; j<w; j++) cin >> s[i][j];
vector<vector<int>> ans(h, vector<int>(w, IINF));
for(int j=0; j<w; j++) ans[h-1][j] = 0;
for(int i=h-2; i>=0; i--){
//左から走査
{
//st1 : value, st2 : pos, st3 : st1->st2への変換点
multiset<int> st1;
set<int> st2;
set<pair<int, int>> st3;
for(int j=0; j<w; j++){
if(s[i][j] == '#'){
st1.clear();
st2.clear();
st3.clear();
}else{
// add under
if(ans[i+1][j] != IINF){
st1.insert(ans[i+1][j]);
st3.insert({ans[i+1][j]+j, j});
}
// move st1 -> st2
if(!st3.empty()){
while((*st3.begin()).fi == j){
int pos = (*st3.begin()).se;
st1.erase(st1.lower_bound(ans[i+1][pos]));
st2.insert(-pos);
st3.erase(st3.begin());
if(st3.empty()) break;
}
}
// calc ans
if(!st1.empty()) ans[i][j] = min(ans[i][j], *st1.begin());
if(!st2.empty()) ans[i][j] = min(ans[i][j], j + *st2.begin());
}
}
}
//右から走査
{
//st1 : value, st2 : pos, st3 : st1->st2への変換点
multiset<int> st1;
set<int> st2;
set<pair<int, int>> st3;
for(int j=w-1; j>=0; j--){
if(s[i][j] == '#'){
st1.clear();
st2.clear();
st3.clear();
}else{
// add under
if(ans[i+1][j] != IINF){
st1.insert(ans[i+1][j]);
st3.insert({-(j-ans[i+1][j]), j});
}
// move st1 -> st2
if(!st3.empty()){
while((*st3.begin()).fi == -j){
int pos = (*st3.begin()).se;
st1.erase(st1.lower_bound(ans[i+1][pos]));
st2.insert(pos);
st3.erase(st3.begin());
if(st3.empty()) break;
}
}
// calc ans
if(!st1.empty()) ans[i][j] = min(ans[i][j], *st1.begin());
if(!st2.empty()) ans[i][j] = min(ans[i][j], *st2.begin() - j);
}
}
}
}
for(int j=0; j<w; j++) cout << ans[0][j] << endl;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T=1;
//cin >> T;
while(T--) solve();
}