結果
| 問題 |
No.2708 Jewel holder
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-22 18:23:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 814 bytes |
| コンパイル時間 | 744 ms |
| コンパイル使用メモリ | 80,148 KB |
| 最終ジャッジ日時 | 2025-02-18 22:06:26 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <iostream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H, W, ans = 0;
cin >> H >> W;
vector<string> G(H);
for (int i = 0; i < H; i++) {
cin >> G[i];
}
int dx[] = {1, 0};
int dy[] = {0, 1};
stack<pair<pair<int, int>, int>> S;
S.push({{0, 0}, 1});
while (!S.empty()) {
auto [xy, now] = S.top();
auto [x, y] = xy;
S.pop();
for (int i = 0; i < 2; i++) {
int a = x + dx[i], b = y + dy[i];
if (a < 0 || b < 0 || a >= H || b >= W || G[a][b] == '#') continue;
int next = now + (G[a][b] == 'o' ? 1 : -1);
if (next >= 0) {
if (a == H - 1 && b == W - 1) {
ans++;
} else {
S.push({{a, b}, next});
}
}
}
}
cout << ans << endl;
}