結果

問題 No.2708 Jewel holder
コンテスト
ユーザー tnakao0123
提出日時 2024-04-30 09:46:42
言語 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  
実行時間 2 ms / 2,000 ms
コード長 1,095 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 393 ms
コンパイル使用メモリ 75,380 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-07-04 15:55:54
合計ジャッジ時間 1,499 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 2708.cc:  No.2708 Jewel holder - yukicoder
 */

#include<cstdio>
#include<map>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_H = 10;
const int MAX_W = 10;

/* typedef */

typedef long long ll;
typedef map<int,ll> mil;

/* global variables */

char fs[MAX_H][MAX_W + 4];
mil ds[MAX_H][MAX_W];

/* subroutines */

/* main */

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

  ds[0][0][1] = 1;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (! ds[y][x].empty()) {
	if (y + 1 < h && fs[y + 1][x] != '#') {
	  int dd = (fs[y + 1][x] == 'o') ? 1 : -1;
	  for (auto [ud, uc]: ds[y][x]) {
	    int vd = ud + dd;
	    if (vd >= 0) ds[y + 1][x][vd] += uc;
	  }
	}
	if (x + 1 < w && fs[y][x + 1] != '#') {
	  int dd = (fs[y][x + 1] == 'o') ? 1 : -1;
	  for (auto [ud, uc]: ds[y][x]) {
	    int vd = ud + dd;
	    if (vd >= 0) ds[y][x + 1][vd] += uc;
	  }
	}
      }

  ll sum = 0;
  for (auto [d, c]: ds[h - 1][w - 1]) sum += c;

  printf("%lld\n", sum);

  return 0;
}
0