結果

問題 No.2708 Jewel holder
ユーザー yansi819
提出日時 2024-04-02 13:09:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 4,342 ms
コンパイル使用メモリ 255,024 KB
最終ジャッジ日時 2025-02-20 19:37:21
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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