結果

問題 No.3071 Double Speedrun
ユーザー umezo
提出日時 2025-03-22 06:05:54
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 674 ms / 6,000 ms
コード長 1,060 bytes
コンパイル時間 3,669 ms
コンパイル使用メモリ 277,564 KB
実行使用メモリ 260,480 KB
最終ジャッジ日時 2025-03-22 06:06:04
合計ジャッジ時間 10,002 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;

int dp[410][410][410];
const int MOD=998244353;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int h,w;
  cin>>h>>w;
  V<string> S(h);
  rep(i,h) cin>>S[i];
  
  auto f=[&](int i,int j,int k,int l)->bool{
    if(i>=h || j>=w || k>=h || l>=w) return false;
    if(S[i][j]=='#' || S[k][l]=='#') return false;
    return true;
  };
  
  dp[1][0][1]=1;
  for(int i=1;i<h;i++) for(int j=0;j<w-1;j++) for(int k=1;k<min(h,w);k++){
    if(dp[i][j][k]==0) continue;
    if(f(i+1,j,i-k+1,j+k)) dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%MOD;
    if(f(i+1,j,i-k,j+k+1)) dp[i+1][j][k+1]=(dp[i+1][j][k+1]+dp[i][j][k])%MOD;
    if(f(i,j+1,i-k+1,j+k)) dp[i][j+1][k-1]=(dp[i][j+1][k-1]+dp[i][j][k])%MOD;
    if(f(i,j+1,i-k,j+k+1)) dp[i][j+1][k]=(dp[i][j+1][k]+dp[i][j][k])%MOD;
  }
  cout<<dp[h-1][w-1][0]<<endl;

  return 0;
}
0