結果

問題 No.2456 Stamp Art
ユーザー Taiki0715Taiki0715
提出日時 2023-09-01 22:50:44
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,570 bytes
コンパイル時間 7,359 ms
コンパイル使用メモリ 155,264 KB
実行使用メモリ 40,184 KB
最終ジャッジ日時 2023-09-01 22:51:16
合計ジャッジ時間 30,876 ms
ジャッジサーバーID
(参考情報)
judge12 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2,077 ms
40,176 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 4,715 ms
40,176 KB
testcase_07 AC 807 ms
40,176 KB
testcase_08 AC 2,780 ms
40,104 KB
testcase_09 AC 4,746 ms
40,184 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

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));
  }
  // 関数の入力のindexは0-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<0の時は0 x>=H y>=Wのときはx=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 > y2の時はswap
  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;
}
0