結果

問題 No.2708 Jewel holder
ユーザー tnakao0123
提出日時 2024-04-30 09:46:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 63,532 KB
最終ジャッジ日時 2025-02-21 09:51:36
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |   scanf("%d%d", &h, &w);
      |   ~~~~~^~~~~~~~~~~~~~~~
main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   for (int y = 0; y < h; y++) scanf("%s", fs[y]);
      |                               ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

/* -*- 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