結果
| 問題 | No.2928 Gridpath | 
| コンテスト | |
| ユーザー |  umezo | 
| 提出日時 | 2024-10-12 16:34:01 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 40 ms / 2,000 ms | 
| コード長 | 1,444 bytes | 
| コンパイル時間 | 3,485 ms | 
| コンパイル使用メモリ | 267,720 KB | 
| 実行使用メモリ | 8,704 KB | 
| 最終ジャッジ日時 | 2024-10-12 16:34:06 | 
| 合計ジャッジ時間 | 4,575 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 | 
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int h,w;
  cin>>h>>w;
  int si,sj,gi,gj;
  cin>>si>>sj>>gi>>gj;
  si--,sj--,gi--,gj--;
  
  map<pair<V<int>,int>,ll> m;
  
  V<int> A(h*w);
  A[si*w+sj]=1;
  m[{A,si*w+sj}]=1;
  queue<pair<V<int>,int>> que;
  que.push({A,si*w+sj});
  while(que.size()){
    auto p=que.front(); que.pop();
    auto B=p.first;
    auto i=p.second/w,j=p.second%w;
    rep(k,4){
      int ni=i+dh[k],nj=j+dw[k];
      if(ni<0 || nj<0 || ni>=h || nj>=w) continue;
      int next=ni*w+nj;
      if(B[next]) continue;
      if(k==0 && ((nj>0 && B[next-1]) || (ni<h-1 && B[next+w]) || (nj<w-1 && B[next+1]))) continue;
      if(k==1 && ((ni>0 && B[next-w]) || (nj<w-1 && B[next+1]) || (ni<h-1 && B[next+w]))) continue;
      if(k==2 && ((nj>0 && B[next-1]) || (ni>0 && B[next-w]) || (nj<w-1 && B[next+1]))) continue;
      if(k==3 && ((ni>0 && B[next-w]) || (nj>0 && B[next-1]) || (ni<h-1 && B[next+w]))) continue;
      B[next]=1;
      m[{B,next}]+=m[p];
      if(next!=gi*w+gj) que.push({B,next});
      B[next]=0;
    }
  }
  ll ans=0;
  for(auto [a,b]:m){
    if(a.second==gi*w+gj) ans+=b;
  }
  cout<<ans<<endl;
  return 0;
}
            
            
            
        