結果

問題 No.2708 Jewel holder
ユーザー yansi819yansi819
提出日時 2024-04-02 13:09:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 4,763 ms
コンパイル使用メモリ 266,492 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-02 13:09:53
合計ジャッジ時間 5,515 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 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 2 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 2 ms
6,548 KB
testcase_17 AC 2 ms
6,548 KB
testcase_18 AC 2 ms
6,548 KB
testcase_19 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

int h, w;
string a[11];
int dx[2] = {1, 0};
int dy[2] = {0, 1};
int ans = 0;

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> a[i];
  queue<pair<int, int>> que;
  que.push({0, 1});
  while (!que.empty()) {
    auto [p, q] = que.front(); que.pop();
    int x = p / w;
    int y = p % w;
    //cout << x << ' ' << y << ' ' << q << endl;
    if (x == h - 1 && y == w - 1) {
      ans++;
      continue;
    }
    for (int i = 0; i < 2; i++) {
      int r = q;
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx >= h || ny >= w || a[nx][ny] == '#') continue;
      if (a[nx][ny] == 'o') r++;
      else if (a[nx][ny] == 'x') r--;
      if (r >= 0) que.push({nx * w + ny, r});
    }
  }
  cout << ans << endl;
  return 0;
}
0