結果
問題 | No.2708 Jewel holder |
ユーザー |
|
提出日時 | 2024-04-27 10:31:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 1,794 ms |
コンパイル使用メモリ | 171,284 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 11:52:02 |
合計ジャッジ時間 | 2,723 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int H, W; cin >> H >> W; vector<string> A(H); rep(i, H) cin >> A[i]; vector<int> dh = {1, 0}; vector<int> dw = {0, 1}; int path = 0; auto dfs = [&](auto dfs, int h, int w, int jewl) { if (A[h][w] == 'o') jewl++; if (A[h][w] == 'x') jewl--; if (jewl < 0) return; if (h == H-1 && w == W-1) { path++; return; } rep(i, 2) { int hNew = h + dh[i]; int wNew = w + dw[i]; if (hNew >= H || wNew >= W) continue; if (A[hNew][wNew] == '#') continue; dfs(dfs, hNew, wNew, jewl); } return; }; dfs(dfs, 0, 0, 0); cout << path << endl; return 0; }