結果

問題 No.2708 Jewel holder
ユーザー a1048576a1048576
提出日時 2024-03-31 13:47:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,257 bytes
コンパイル時間 4,008 ms
コンパイル使用メモリ 242,868 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 13:47:18
合計ジャッジ時間 4,592 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 1 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 2 ms
6,548 KB
testcase_15 AC 2 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all> 
using mint = atcoder::modint998244353;
#define int long long
signed main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; i++) cin >> s[i];
  vector<vector<vector<int>>> dp(h,vector<vector<int>>(w,vector<int>(h*w+1,0)));
  dp[0][0][1]++;
  deque<pair<int,int>> q;
  q.push_back({0,0});
  vector<vector<bool>> v(h,vector<bool>(w,false));
  vector<vector<bool>> z = v;
  z[0][0] = true;
  while(q.size() > 0) {
    int x,y;
    tie(x,y) = q.front();
    v[x][y] = true;
    q.pop_front();
    if(x != h-1 && !v[x+1][y] && s[x+1][y] != '#') {
      int t = 1;
      if(s[x+1][y] == 'x') t-=2;
      for(int i = 0; i <= h*w; i++) {
        if(i+t >= 0 && i+t <= h*w) dp[x+1][y][i+t]+=dp[x][y][i];
      }
      if(!z[x+1][y]) q.push_back({x+1,y});
      z[x+1][y] = true;
    }
    if(y != w-1 && !v[x][y+1] && s[x][y+1] != '#') {
      int t = 1;
      if(s[x][y+1] == 'x') t-=2;
      for(int i = 0; i <= h*w; i++) {
        if(i+t >= 0 && i+t <= h*w) dp[x][y+1][i+t]+=dp[x][y][i];
      }
      if(!z[x][y+1]) q.push_back({x,y+1});
      z[x][y+1] = true;
    }
  }
  int ans = 0;
  for(int i = 1; i <= h*w; i++) ans+=dp[h-1][w-1][i];
  cout << ans << endl;
}
0