結果

問題 No.3071 Double Speedrun
コンテスト
ユーザー tnakao0123
提出日時 2025-03-24 11:54:43
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 272 ms / 6,000 ms
コード長 1,537 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 189 ms
コンパイル使用メモリ 57,392 KB
実行使用メモリ 9,200 KB
最終ジャッジ日時 2026-07-07 21:00:38
合計ジャッジ時間 3,021 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3071.cc:  No.3071 Double Speedrun - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_H = 400;
const int MAX_W = 400;
const int MAX_WW = MAX_W * MAX_W;
const int MOD = 998244353;

/* typedef */

/* global variables */

char fs[MAX_H][MAX_W + 4];
int dp[2][MAX_WW];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", fs[i]);

  int maxi = h + w - 3, ww = w * w;
  int cur = 0, nxt = 1;
  dp[0][0 * w + 1] = 1;
  
  for (int i = 1; i < maxi; i++) {
    fill(dp[nxt], dp[nxt] + ww, 0);
    
    int x0 = min(i, w - 1) - 1, y0 = i - x0;
    for (; x0 >= 0 && y0 < h; x0--, y0++)
      if (fs[y0][x0] == '.') {
	int x1 = min(i, w - 1), y1 = i - x1;
	for (; x1 > x0; x1--, y1++)
	  if (fs[y1][x1] == '.') {
	    int u = x0 * w + x1;
	    if (dp[cur][u]) {
	      //printf(" i=%d,x0=%d,x1=%d: %d\n", i, x0, x1, dp[cur][u]);

	      for (int di0 = 0; di0 < 2; di0++) {
		int vy0 = y0 + (1 - di0), vx0 = x0 + di0;
		if (vy0 < h && vx0 < w && fs[vy0][vx0] == '.')
		  for (int di1 = 0; di1 < 2; di1++) {
		    int vy1 = y1 + (1 - di1), vx1 = x1 + di1;
		    if (vy1 < h && vx0 < w && fs[vy1][vx1] == '.' &&
			vx0 != vx1) {
		      int v = vx0 * w + vx1;
		      addmod(dp[nxt][v], dp[cur][u]);
		    }
		  }
	      }
	    }
	  }
      }
    swap(cur, nxt);
  }

  printf("%d\n", dp[cur][(w - 2) * w + (w - 1)]);
  
  return 0;
}
0