結果

問題 No.2456 Stamp Art
ユーザー Taiki0715Taiki0715
提出日時 2023-09-01 22:50:44
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 4,570 bytes
コンパイル時間 7,616 ms
コンパイル使用メモリ 191,076 KB
実行使用メモリ 45,612 KB
最終ジャッジ日時 2025-01-03 10:39:04
合計ジャッジ時間 72,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;}
istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;}
#endif
using ll=long long;
using ull=unsigned long long;
using P=pair<ll,ll>;
template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>;
template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);}
template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);}
template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;}
template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;}
template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;}
template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;}
template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;}
#define reps(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) reps(i,0,n)
#define all(x) x.begin(),x.end()
#define pcnt(x) __builtin_popcount(x)
ll myceil(ll a,ll b){return (a+b-1)/b;}
template<typename T,size_t n,size_t id=0>
auto vec(const int (&d)[n],const T &init=T()){
if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init));
else return init;
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) static_cast<void>(0)
template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;}
#endif
void SOLVE();
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
clock_t start=clock();
#endif
int testcase=1;
//cin>>testcase;
for(int i=0;i<testcase;i++){
SOLVE();
}
#ifdef LOCAL
cout<<"time:";
cout<<(clock()-start)/1000;
cout<<"ms\n";
#endif
}
template <typename T>
struct BinaryIndexedTree2D {
int H, W;
vector<vector<T>> bit;
BinaryIndexedTree2D(int _H, int _W) : H(_H + 1), W(_W + 1) {
bit.resize(H + 3, vector<T>(W + 3, 0));
}
// index0-origin
// (x,y)w
//
void add(int x, int y, T w) {
if (x < 0 || x >= H || y < 0 || y >= W) return;
for (int a = (++y, ++x); a <= H; a += a & -a) {
for (int b = y; b <= W; b += b & -b) {
bit[a][b] += w;
}
}
}
// imos[(x1,y1) , (x2,y2)]w
void imos(int x1, int y1, int x2, int y2, T w) {
add(x1, y1, w);
add(x1, y2 + 1, -w);
add(x2 + 1, y1, -w);
add(x2 + 1, y2 + 1, w);
}
// [(0,0) , (x,y)] 
// x,y<00 x>=H y>=Wx=H-1,y=W-1
// ( imos (x,y) )
T sum(int x, int y) {
if (x < 0 || y < 0) return 0;
if (x >= H) x = H - 1;
if (y >= W) y = W - 1;
T ret = 0;
for (int a = (++y, ++x); a > 0; a -= a & -a) {
for (int b = y; b > 0; b -= b & -b) {
ret += bit[a][b];
}
}
return ret;
}
// [(x1,y1) , (x2,y2)]
// x1 > x2, y1 > y2swap
T sum(int x1, int y1, int x2, int y2) {
if (x1 > x2 || y1 > y2) return T(0);
return sum(x2, y2) - sum(x2, y1 - 1) - sum(x1 - 1, y2) +
sum(x1 - 1, y1 - 1);
}
};
/*
* @brief Binary Indexed Tree
*/
vector<vector<int>>sum;
int get(int a,int b,int c,int d){
int ret=sum[c][d];
if(a)ret-=sum[a-1][d];
if(b)ret-=sum[c][b-1];
if(a&&b)ret+=sum[a-1][b-1];
return ret;
}
void SOLVE(){
int h,w;
cin>>h>>w;
vector<string>s(h);
cin>>s;
sum.resize(h,vector<int>(w,0));
rep(i,h)rep(j,w){
sum[i][j]=s[i][j]=='.';
if(i)sum[i][j]+=sum[i-1][j];
if(j)sum[i][j]+=sum[i][j-1];
if(i&&j)sum[i][j]-=sum[i-1][j-1];
}
int ok=1,ng=min(h,w)+1;
while(ng-ok>1){
int mid=(ok+ng)/2;
BinaryIndexedTree2D<int>BIT(h,w);
vector<vector<bool>>hidariue(h,vector<bool>(w,false));
vector<vector<bool>>okeru(h,vector<bool>(w,false));
rep(i,h)rep(j,w)if(s[i][j]=='#'){
if(i+mid<=h&&j+mid<=w){
if(get(i,j,i+mid-1,j+mid-1)==0)hidariue[i][j]=okeru[i][j]=true,BIT.add(i,j,1);
}
if(BIT.sum(max(0,i-mid+1),max(0,j-mid+1),i,j)!=0)okeru[i][j]=true;
}
bool ok2=true;
rep(i,h)rep(j,w)if(s[i][j]=='#'&&!okeru[i][j])ok2=false;
debug(okeru,hidariue);
(ok2?ok:ng)=mid;
}
cout<<ok<<endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0