結果

問題 No.402 最も海から遠い場所
コンテスト
ユーザー Glemim
提出日時 2026-11-22 19:26:01
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 869 ms / 3,000 ms
+ 962µs
コード長 16,112 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,724 ms
コンパイル使用メモリ 404,808 KB
実行使用メモリ 191,104 KB
最終ジャッジ日時 2026-11-22 19:26:17
合計ジャッジ時間 12,385 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
constexpr long long INF=2002002002002002002LL;
constexpr double PI=3.14159265358979323846;
constexpr long long dx[]={ 1, 0, -1,  0, 1, -1, -1,  1, 0};
constexpr long long dy[]={ 0, 1,  0, -1, 1,  1, -1, -1, 0};
constexpr string yesno[]={"No\n","Yes\n"};
constexpr char DRUL[]="DRUL";
constexpr unsigned long long TEN[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000,10000000000000000000ULL};
using ll=long long;
using ull=unsigned long long;
using mint=atcoder::modint998244353;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class U,class V> pair<U,V> operator+(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first+rhs.first,lhs.second+rhs.second}; }
template<class U,class V> pair<U,V> operator-(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first-rhs.first,lhs.second-rhs.second}; }
template<class U,class V> pair<U,V> &operator+=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs+rhs; }
template<class U,class V> pair<U,V> &operator-=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs-rhs; }
template<class T> pair<T,T> operator*(const pair<T,T> &lhs, const T &rhs) { return {lhs.first*rhs,lhs.second*rhs}; }
template<class T> pair<T,T> operator*(const T &lhs, const pair<T,T> &rhs) { return {lhs*rhs.first,lhs*rhs.second}; }
template<class T> pair<T,T> operator/(const pair<T,T> &lhs, const T &rhs) { return {lhs.first/rhs,lhs.second/rhs}; }
template<class T> T operator*(const pair<T,T> &lhs, const pair<T,T> &rhs) { return lhs.first*rhs.second-rhs.first*lhs.second; }
template<class T> inline T hypotsq(const pair<T,T> &p) { return p.first*p.first+p.second*p.second; }
template<class T> inline double hypot(const pair<T,T> &p) { return hypot<double>(p.first,p.second); }
template<class T> inline T hypotsq(T x, T y) { return x*x+y*y; }
template<class T> inline T hypotsq(T px, T py, T qx, T qy) { return hypotsq(qx-px,qy-py); }
template<class T> inline double hypot(T px, T py, T qx, T qy) { return hypot<double>(qx-px,qy-py); }
template<int M> istream &operator>>(istream &is, atcoder::static_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::static_modint<M> &x) { return os<<x.val(); }
template<int M> istream &operator>>(istream &is, atcoder::dynamic_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::dynamic_modint<M> &x) { return os<<x.val(); }
istream &operator>>(istream &is, __int128_t &x) { string S; is>>S; x=0; bool neg=false; for (auto &c : S) { if (c=='-') neg=true; else x=x*10+c-'0'; } if (neg) x=-x; return is; }
ostream &operator<<(ostream &os, __int128_t x) { if (x==0) return os<<0; if (x<0) os<<'-', x=-x; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S),end(S)); return os<<S; }
istream &operator>>(istream &is, __uint128_t &x) { string S; is>>S; x=0; for (auto &c : S) x=x*10+c-'0'; return is; }
ostream &operator<<(ostream &os, __uint128_t x) { if (x==0) return os<<0; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S), end(S)); return os<<S; }
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p);
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p);
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t);
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t);
template<class T> istream &operator>>(istream &is, vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const optional<T> &x);
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p) { return is>>p.first>>p.second; }
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p) { return os<<p.first<<' '<<p.second; }
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t) { apply([&](auto &...args) { ((is>>args), ...); },t); return is; }
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t) { apply([&](auto &...args) { int n=0; ((os<<(n++?" ":"")<<args), ...); },t); return os;}
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is>>x; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i=0,s=(int)v.size();i<s;++i) os<<(i?" ":"")<<v[i]; return os; }
template<class T> ostream &operator<<(ostream &os, const set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const unordered_set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const multiset<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const list<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const stack<T> &v) { stack<T> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const queue<T> &v) { queue<T> u=v; while (!u.empty()) { os<<u.front(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const deque<T> &v) { deque<T> u=v; while (!u.empty()) { os<<u.front(); u.pop_front(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U,class V> ostream &operator<<(ostream &os, const priority_queue<T,U,V> &v) { priority_queue<T,U,V> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U> ostream &operator<<(ostream &os, const map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T,class U> ostream &operator<<(ostream &os, const unordered_map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const optional<T> &x) {  if (x.has_value()) return os<<x.value(); return os<<"-1"; }
template<class T,class U> inline T floor(const T &a, const U &b) { return a/b-(a%b && (a^b)< 0); }
template<class T,class U> inline T ceil (const T &a, const U &b) { return a/b+(a%b && (a^b)>=0); }
inline double radian(double deg) { return (PI/180.0)*deg; }
inline double degree(double rad) { return (180.0/PI)*rad; }
inline long long popcount(unsigned long long x) { return __builtin_popcountll(x); }
inline long long height(unsigned long long x) { if (x==0) return 0LL; return 64LL-__builtin_clzll(x); }
inline long long ctz(unsigned long long x) { return __builtin_ctzll(x); }
inline long long lsb(long long b) { return b&-b; }
template<class T> long long sgn(const T &x) { if (x<0) return -1; return x>0; }
template<class T> inline typename enable_if<is_integral_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a%b; if (res<0) res+=b; return res; }
template<class T> inline typename enable_if<is_floating_point_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a-floor(a/b)*b; if (res<0.0) res+=b; return res; }
template<class T> inline bool inlr(const T &l, const T &x, const T &r) noexcept { return (l<=x && x<r); }
template<class T> bool isinc(T first, T second) { return first<=second; }
template<class T,class ...Rest> bool isinc(T first, T second, const Rest ...rest) { return first<=second && isinc(second,rest...); }
long long safe_mul() noexcept { return 1LL; }
template<class ...Rest> long long safe_mul(long long a, Rest ...rest) noexcept { if (a==0LL) return 0LL; long long b=safe_mul(rest...); if (b==0LL) return 0LL; if (INF/a/b==0LL) return ((0LL<a)^(0LL<b) ? -INF : INF); return a*b; }
template<class T> void println(T item) { cout<<item<<'\n'; }
template<class T,class ...Rest> void println(T item, Rest ...rest) { cout<<item<<' '; println(rest...); }
template<class T> void dump(T item) { cerr<<item<<'\n'; }
template<class T,class ...Rest> void dump(T item, Rest ...rest) { cerr<<item<<' '; dump(rest...); }
long long safe_lcm(long long a, long long b) { if (a==0 || b==0) return 0LL; if (a<0) a=-a; if (b<0) b=-b; if (a>=INF || b>=INF) return INF; return safe_mul(a/gcd(a,b),b); }
template<class Res=long long> vector<Res> mkiota(int n, Res val=0) { vector<Res> res(n); iota(begin(res),end(res),val); return res; }
template<class T> T mkrev(const T &v) { T res=v; reverse(res.begin(),res.end()); return res; }
template<class T> vector<T> mksum(const vector<T> &v) { int s=v.size(); vector<T> res(s+1); for (int i=0;i<s;++i) res[i+1]=res[i]+v[i]; return res; }
template<class T> vector<T> mkdif(const vector<T> &v) { int s=v.size(); vector<T> res(s-1); for (int i=0;i+1<s;++i) res[i]=v[i+1]-v[i]; return res; }
template<class T> vector<T> mkuni(const vector<T> &v) { auto res=v; sort(res.begin(),res.end()); res.erase(unique(res.begin(),res.end()),res.end()); return res; }
template<class Res=long long,class T> vector<Res> mkinv(const vector<T> &v) { vector<Res> res(*max_element(v.begin(),v.end())+1,-1); for (int i=0,s=v.size();i<s;++i) res[v[i]]=i; return res; }
template<class Res=long long,class F> vector<Res> mkord(int n, F f) { vector<Res> res(n); iota(res.begin(),res.end(),0); stable_sort(res.begin(),res.end(),f); return res; }
template<class T> map<T,long long> mkcnt(const vector<T> &v) { map<T,long long> res; for (const auto &x : v) res[x]++; return res; }
template<class T,class F> vector<vector<T>> mksplit(const vector<T> &v, F f) { if (v.size()==0) return {}; vector<vector<T>> res{{v[0]}}; for (int i=0,s=v.size();i+1<s;++i) { if (f(v[i],v[i+1])) res.push_back({}); res.back().push_back(v[i+1]); } return res; }
template<class T> vector<pair<T,long long>> mkrle(const vector<T> &v) { int n=v.size(); vector<pair<T,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && v[i]==v[i+1]) { cnt++; i++; } res.emplace_back(v[i],cnt); } return res; }
vector<pair<char,long long>> mkrle(const string &s) { int n=s.size(); vector<pair<char,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && s[i]==s[i+1]) { cnt++; i++; } res.emplace_back(s[i],cnt); } return res; }
template<class T> atcoder::fenwick_tree<T> mkfen(const vector<T> &v) { int s=v.size(); atcoder::fenwick_tree<T> res(s); for (int i=0;i<s;++i)  res.add(i,v[i]); return res; }
template<class T> T min(const vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T> T max(const vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T> inline void sort(T &v, bool rev=false) { rev ? sort(v.rbegin(),v.rend()) : sort(v.begin(),v.end()); }
template<class T,class U> long long count(const T &v, const U &item) { return count(v.begin(),v.end(),item); }
template<class T> inline long long count_in_range(const vector<T> &v, const T &l, const T &r) { return lower_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l); }
template<class T> inline long long lob(const vector<T> &v, const T &x) { return lower_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> inline long long upb(const vector<T> &v, const T &x) { return upper_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> optional<long long> minel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]<v[b]; })[k]; }
template<class T> optional<long long> maxel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]>v[b]; })[k]; }
template<class T> T flatten(const vector<T> &vv) { T res; for (const T &v : vv) res.insert(res.end(),v.begin(),v.end()); return res; }
vector<long long> binary_split(long long x) { assert(x>=0); vector<long long> res; long long k=1; while (x>0) { long long y=min(k,x); res.push_back(y); x-=y; k<<=1; } return res; }
template<class T> T arithmetic_series(T a, T d, T n) { return (a*2+(n-1)*d)*n/2; }
template<class T> long long hamming_distance(const T &a, const T &b) { assert(a.size()==b.size()); auto ita=a.begin(); auto itb=b.begin(); int res=0; while (ita!=a.end()) if (*ita++!=*itb++) res++; return res; }
template<class T> long long get_period(const T &v) { int n=v.size(); vector<int> z=atcoder::z_algorithm(v); for (int i=1;i<=n/2;++i) if (n%i==0 && z[i]==n-i) return i; return n; }
template<class T> void cumulative_min(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=min(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=min(v[i],v[i+1]); }
template<class T> void cumulative_max(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=max(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=max(v[i],v[i+1]); }
template<class T> void repeat_vector(vector<T> &v, int count=2) { assert(count>=0); if (count==0) { v.clear(); return; } count--; int original_size=v.size(); while (count--) v.insert(v.end(),v.begin(),v.begin()+original_size); }
template<class T> long long longest_continuum(const vector<T> &v) { if (v.empty()) return 0; long long res=1; long long now=1; int n=v.size(); for (int i=1;i<n;++i) if (v[i]==v[i-1]) chmax(res,++now); else now=1; return res; }
template<class T> long long longest_continuum(const vector<T> &v, const T &item) { long long res=0; long long now=0; for (auto &x : v) if (x==item) chmax(res,++now); else now=0; return res; }
template<class T> long long lis_len(const vector<T> &v, bool strict=true) { vector<T> dp; for (auto &x : v) { auto it=strict ? lower_bound(dp.begin(),dp.end(),x) : upper_bound(dp.begin(),dp.end(),x); if (it==dp.end()) dp.push_back(x); else *it=x; } return dp.size(); }
template<class T> long long inversions(vector<T> &v) { map<T,int> cc; for (auto &x : v) cc[x]=0; int M=0; for (auto &[key,val] : cc) val=M++; long long res=0; atcoder::fenwick_tree<long long> fen(M); for (auto &x : v) { int y=cc[x]; res+=fen.sum(y+1,M); fen.add(y,1); } return res; }
long long ctok(char d) { switch (d) { case 'D': return 0; case 'R': return 1; case 'U': return 2; case 'L': return 3; } return -1; }
template<class T> T min_op(T a, T b) { return min(a,b); }
template<class T> T max_op(T a, T b) { return max(a,b); }
template<class T> using min_segtree=atcoder::segtree<T,min_op<T>,numeric_limits<T>::max>;
template<class T> using max_segtree=atcoder::segtree<T,max_op<T>,numeric_limits<T>::lowest>;

template<class T> void rotate_grid(std::vector<T> &grid, bool clockwise=true) {
  int h=grid.size();
  int w=grid[0].size();
  std::vector<T> res(w,T(h,0));
  for (int i=0;i<w;++i) {
    for (int j=0;j<h;++j) {
      res[i][j]=(clockwise ? grid[h-1-j][i] : grid[j][w-1-i]);
    }
  }
  grid=std::move(res);
}

int main() {
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  cin>>S;

  vector<vector<vector<int>>> dp(4,vector<vector<int>>(H,vector<int>(W,0)));
  for (int h=0;h<4;++h) {
    for (int x=H-1;x>=0;--x) {
      for (int y=W-1;y>=0;--y) {
        if (S[x][y]=='.') continue;
        int r=0;
        int d=0;
        int dr=0;
        if (y!=W-1) r=dp[h][x][y+1];
        if (x!=H-1) d=dp[h][x+1][y];
        if (x!=H-1 && y!=W-1) dr=dp[h][x+1][y+1];
        dp[h][x][y]=min({r,d,dr})+1;
      }
    }
    rotate_grid(S);
    rotate_grid(dp[0]);
    rotate_grid(dp[1]);
    rotate_grid(dp[2]);
    rotate_grid(dp[3]);
    swap(H,W);
  }
  int ans=0;
  for (int x=0;x<H;++x) {
    for (int y=0;y<W;++y) {
      chmax(ans,min({dp[0][x][y],dp[1][x][y],dp[2][x][y],dp[3][x][y]}));
    }
  }
  cout<<ans<<endl;

}
0