結果

問題 No.3850 作門ハッカソン
コンテスト
ユーザー irinoirino
提出日時 2026-12-04 23:07:49
言語 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  
実行時間 496 ms / 2,000 ms
+ 419µs
コード長 7,290 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,125 ms
コンパイル使用メモリ 258,680 KB
実行使用メモリ 25,076 KB
最終ジャッジ日時 2026-12-04 23:07:56
合計ジャッジ時間 5,861 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from main.cpp:24:
/home/linuxbrew/.linuxbrew/Cellar/gcc@15/15.3.0/include/c++/15/cstdbool:50:6: warning: #warning "<cstdbool> is deprecated in C++17, remove the #include" [-Wcpp]
   50 | #    warning "<cstdbool> is deprecated in C++17, remove the #include"
      |      ^~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <tuple>
#include <map>
#include <bit>
#include <array>
#include <limits>
#include <type_traits>
#include <utility>
#include <functional>
#include <fstream>
#include <climits>
#include <numeric>
#include <cassert>
#include <cstdbool>
#include <cstdint>
#include <random>
//#include <atcoder/all>

#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define orep(i,n) for(ll i=1;i<=(n);i++)

#define nfor(i,s,n) for(ll i=(s);i<(n);i++)
#define dfor(i,s,n) for(ll i=(s)-1;i>=n;i--)
#define INF 2000000000000000000//9223372036854775807

#define all(a)  a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

#define pb push_back
#define pob pop_back

#define vc vector

#define for_sz(s) (long long)(s.size())

#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define YN {cout << "Yes" << endl;}else{cout << "No" << endl;}
#define dame cout << -1 << endl;

#define vc_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define vc_remove(v,x) v.erase(remove(v.begin(), v.end(),x), v.end())
#define vc_rotate(v) rotate(v.begin(), v.begin()+1, v.end())

#define pop_cnt(s) ll(popcount(uint64_t(s)))
#define next_p(v) next_permutation(v.begin(),v.end())

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll,ll>;
using vvvvvl = vector<vector<vector<vector<vector<ll> > > > >;
using vvvvl = vector<vector<vector<vector<ll> > > >;
using vvvl = vector<vector<vector<ll> > >;
using vvl = vector<vector<ll> >;
using vl = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool> >;
using Graph = vector<vector<ll> >;

template<class T> using pq = priority_queue<T,vc<T>,less<T> >;
template<class T> using pq_g = priority_queue<T,vc<T>,greater<T> >;

ll dx[4] = {0,1,0,-1};ll ddx[8] = {1,1,0,-1,-1,-1,0,1};
ll dy[4] = {1,0,-1,0};ll ddy[8] = {0,1,1,1,0,-1,-1,-1};

bool out_grid(ll i, ll j, ll h, ll w){//trueならcontinueする
    return(!(0 <= i && i < h && 0 <= j && j<w));
}

template<class T>
void cutoutV(vc<vc<T>> &G, ll H, ll W, ll mx, ll Mx, ll my, ll My){
    if(!(0 <= mx && mx < H && 0 < Mx && Mx <= H && mx < Mx))return;
    if(!(0 <= my && my < W && 0 < My && My <= W && my < My))return;

    rep(i,Mx - mx)rep(j,My - my){
        G[i][j] = G[i + mx][j + my];
    }
    G.resize(Mx - mx, vc<T>(My - my));
    return;
}

ll modpow(ll x,ll y,ll m){
    ll a = x;
    a %= m;
    ll cnt = 0;
    ll ans = 1;
    while(y > 0){
        if((1ll << cnt) & y){
            y ^= (1ll << cnt);
            ans *= a;
            ans %= m;
        }
        a = a*a;
        a %= m;
        cnt++;
    }
    return ans;
}

ll npow(ll x,ll y){
    ll a = x;
    ll cnt = 0;
    ll ans = 1;
    while(y > 0){
        if((1ll << cnt) & y){
            y ^= (1ll << cnt);
            ans *= a;
        }
        a = a*a;
        cnt++;
    }
    return ans;
}

struct Edge {
    ll to;
    ll cost;
};

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// ai+bj=g
// ai+bj=gcd(a,b)なるi,jを求める
ll extgcd(ll a, ll b, ll& i, ll& j) {
    if (b == 0) { i = 1; j = 0; return a;}
    ll p = a/b, g = extgcd(b,a-b*p,j,i);
    j -= p*i;
    return g;
}

vl topological_sort(const vvl& G){
    ll N = (ll)G.size();
    vl indeg(N, 0), order;
    queue<ll> que;
    rep(u, N){
        for(ll v : G[u]) indeg[v]++;
    }
    rep(i, N){
        if(indeg[i] == 0) que.push(i);
    }
    while(!que.empty()){
        ll u = que.front();
        que.pop();
        order.pb(u);
        for(ll v : G[u]){
            indeg[v]--;
            if(indeg[v] == 0) que.push(v);
        }
    }
    return order;
}

ll MOD = 998244353;

void print(ld x){printf("%.20Lf\n", x);}

//using mint = modint998244353;
////////////////////////////////////////////////////////////////
// 自分用ライブラリ https://github.com/Gen1729/my-atcoder-library

using tup2=tuple<ll,ll>;
#define tup make_tuple


struct IntervalSet{
  set<tup2> s;
  IntervalSet(){
    s.insert(tup(-INF,-INF));
    s.insert(tup(INF,INF));
  }
  void on_ins(ll l,ll r){
    if(l>=r) return;
    //自由に記入 [l,r)が挿入された時
  }
  void on_rem(ll l,ll r){
    if(l>=r) return;
    //自由に記入 [l,r)が削除された時
  }
  set<tup2>::iterator find(ll x){
    auto it=s.lower_bound(tup(x,INF));
    it--;
    auto [l,r]=*it;
    if(l<=x&&x<r) return it;
    return s.end();
  }
  tup2 insert(ll l,ll r){
    if(l>=r) return tup(0,0);
    auto it=s.lower_bound(tup(l,-INF));
    it--;
    if(get<1>(*it)>=l){
      on_rem(get<0>(*it),get<1>(*it));
      l=get<0>(*it);
      r=max(r,get<1>(*it));
      s.erase(it);
    }
    it=s.lower_bound(tup(l,-INF));
    while(get<0>(*it)<=r){
      on_rem(get<0>(*it),get<1>(*it));
      r=max(r,get<1>(*it));
      s.erase(it++);
    }
    on_ins(l,r);
    s.insert(tup(l,r));
    return tup(l,r);
  }
  void remove(ll l,ll r){
    if(l>=r) return;
    auto it=s.lower_bound(tup(l,-INF));
    it--;
    if(get<1>(*it)>l){
      tup2 left=*it;
      on_rem(get<0>(left),get<1>(left));
      s.erase(it);
      if(get<0>(left)<l){
        on_ins(get<0>(left),l);
        s.insert(tup(get<0>(left),l));
      }
      if(get<1>(left)>r){
        on_ins(r,get<1>(left));
        s.insert(tup(r,get<1>(left)));
      }
    }
    it=s.lower_bound(tup(l,-INF));
    while(get<0>(*it)<r){
      tup2 right=*it;
      on_rem(get<0>(right),get<1>(right));
      s.erase(it++);
      if(get<1>(right)>r){
        on_ins(r,get<1>(right));
        s.insert(tup(r,get<1>(right)));
        break;
      }
    }
  }
  bool same(ll x,ll y){
    auto it=find(x);
    if(it==s.end()) return false;
    auto [l,r]=*it;
    return (l<=y&&y<r);
  }
  ll size(){
    return (ll)s.size()-2;
  }
};


void solve(){
    ll H,W;
    cin >> H >> W;

    vc<vc<char>> S(H,vc<char>(W));

    rep(i,H)rep(j,W)cin >> S[i][j];

    vvl idx(H);

    rep(i,H){
        rep(j,W){
            if(S[i][j] == '#' || S[i][j] == '?')idx[i].pb(j);
        }
    } 

    rep(i,H-1){
        IntervalSet is;
        is.insert(0,W);
        rep(j,W){
            if(S[i][j] == '.')is.remove(j,j+1);
        } 

        for(auto [l,r] : is.s){
            if(l == -INF || l == INF)continue;

            if(r - l <= 2)continue;

            nfor(j,l+1,r-1){
                if(S[i+1][j] == '.' || S[i+1][j] == '?'){
                    ll itl = lower_bound(all(idx[i+1]),j+1) - idx[i+1].begin();

                    if(itl == idx[i+1].size())continue;

                    ll itl2 = lower_bound(all(idx[i+1]),l) - idx[i+1].begin();

                    if(idx[i+1][itl] < r){
                        if(idx[i+1][itl2] < j){
                            YES
                            return;
                        }
                    }
                }
            }
        }
    }

    NO
}

int main(){
    ll T;
    cin >> T;

    while(T--){
        solve();
    }
}
0