結果

問題 No.3850 作門ハッカソン
コンテスト
ユーザー eQe
提出日時 2026-12-04 23:59:10
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 70 ms / 2,000 ms
+ 590µs
コード長 4,893 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,595 ms
コンパイル使用メモリ 360,344 KB
実行使用メモリ 57,980 KB
最終ジャッジ日時 2026-12-04 23:59:17
合計ジャッジ時間 5,801 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/*
#include<kyopro/master>
void self::main(){
  multi_test_cases
  LL(H,W);
  auto s=sinen(H,".#?");
  vec g(3,H,W,int{});
  
  fo(i,H)fo(j,W){
    g[s[i][j]][i][j]=1;
    if(s[i][j]==2){
      g[0][i][j]=1;
      g[1][i][j]=1;
    }
  }
  fo(f,2)zeta(g[f]);
  
  fo(i,H-1)fo(j,W-1){
    if(s[i][j]==0)continue;
    if(s[i][j+1]==0)continue;
    if(s[i+1][j]==0)continue;
    if(s[i+1][j+1]==1)continue;
    
    ll k=binary_search_last_true(j+1,W,[&](ll k){
      return rectangle_sum(g[1],i,i+1,j+1,k+1)==k-j;
    });
    
    ll l=binary_search_first_false(j+1,W,[&](ll l){
      return rectangle_sum(g[1],i+1,i+2,j+2,l+1)==0;
    });
    
    if(l<=k)done(Yes());
  }
  ppNo();
}
*/

#include<bits/stdc++.h>
using namespace std;
namespace self{void main();void sub();void pp(auto&&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define eb emplace_back
#define done(...) return pp(__VA_ARGS__)
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define FO(n) for(ll IJK=n;IJK-->0;)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define multi_test_cases LL(T);FO(T)sub();}void self::sub(){
namespace self{
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
const string newline{char(10)};
void lin(auto&...a){(cin>>...>>a);}
auto Yes(bool p=1){return p?"Yes":"No";}
auto No(){return Yes(0);}
void ppNo(){cout<<No()<<newline;}
constexpr auto abs(auto x){return x<0?-x:x;}
ll binary_search_first_false(ll o,ll x,auto&&f){while(abs(o-x)>1)(f((o+x)/2)?o:x)=(o+x)/2;return x;}
ll binary_search_last_true(ll o,ll x,auto&&f){while(abs(o-x)>1)(f((o+x)/2)?o:x)=(o+x)/2;return o;}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace self{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<vectorial V>struct core_t_helper<V>{using type=typename core_t_helper<typename V::value_type>::type;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  static constexpr int D=depth<V>+1;
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const auto&...a)requires(sizeof...(a)>=3){assign_all(a...);}
  void assign_all(const auto&...a){if constexpr(sizeof...(a)==D){ }else*this=make(a...);}
  static auto make(ll n,const auto&...a){
    if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
    else return vec<decltype(make(a...))>(n,make(a...));
  }
  auto&operator+=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]+=u[i];return v;}
  ll size()const{return vector<V>::size();}
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
template<vectorial V>void zeta(V&&v){if constexpr(depth<remove_cvref_t<V>>>1)fe(v,e)zeta(e);fo(i,v.size()-1)v[i+1]+=v[i];}
auto sin(){string s;lin(s);return s;}
template<class T=ll>auto sinen(const string&b){assert(b.size()>1);vec<T>r;fe(sin(),e)r.eb(b.find_first_of(e));return r;}
template<class T=ll>auto sinen(ll n,const string&b){vec<vec<T>>r;FO(n)r.eb(sinen<T>(b));return r;}
}
namespace self {
  template<class T>auto rectangle_sum(const vec<vec<T>>&v,ll a,ll b,ll c,ll d){
    assert(0<=a&&a<=b&&b<=v.size());
    assert(0<=c&&c<=d&&d<=v[0].size());

    T res=0;
    if(b&&d)res+=v[b-1][d-1];
    if(a&&d)res-=v[a-1][d-1];
    if(b&&c)res-=v[b-1][c-1];
    if(a&&c)res+=v[a-1][c-1];
    return res;
  }
}
void self::pp(auto&&...a){const char*c="";((cout<<c<<a,c=" "),...);cout<<'\n';}
void self::main(){
  multi_test_cases
  LL(H,W);
  auto s=sinen(H,".#?");
  vec g(3,H,W,int{});

  fo(i,H)fo(j,W){
    g[s[i][j]][i][j]=1;
    if(s[i][j]==2){
      g[0][i][j]=1;
      g[1][i][j]=1;
    }
  }
  fo(f,2)zeta(g[f]);

  fo(i,H-1)fo(j,W-1){
    if(s[i][j]==0)continue;
    if(s[i][j+1]==0)continue;
    if(s[i+1][j]==0)continue;
    if(s[i+1][j+1]==1)continue;

    ll k=binary_search_last_true(j+1,W,[&](ll k){
      return rectangle_sum(g[1],i,i+1,j+1,k+1)==k-j;
    });

    ll l=binary_search_first_false(j+1,W,[&](ll l){
      return rectangle_sum(g[1],i+1,i+2,j+2,l+1)==0;
    });

    if(l<=k)done(Yes());
  }
  ppNo();
}
0