結果
問題 | No.2708 Jewel holder |
ユーザー |
![]() |
提出日時 | 2024-03-31 20:17:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,290 bytes |
コンパイル時間 | 1,874 ms |
コンパイル使用メモリ | 203,612 KB |
最終ジャッジ日時 | 2025-02-20 18:18:35 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; const vector<int> dx = {1, 0}; const vector<int> dy = {0, 1}; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector<vector<vector<int>>> dp(H, vector<vector<int>>(W, vector<int>(H + W + 1, 0))); dp[0][0][1] = 1; for (int x = 0; x < H; x++) { for (int y = 0; y < W; y++) { for (int i = 0; i <= H + W; i++) { for (int j = 0; j < 2; j++) { int nx = x + dx[j]; int ny = y + dy[j]; if (nx >= H || ny >= W) { continue; } if (S[nx][ny] == '#') { continue; } int ni = S[nx][ny] == 'o' ? 1 : -1; if (i + ni < 0) { continue; } dp[nx][ny][i + ni] += dp[x][y][i]; } } } } int ans = 0; for (int i = 0; i <= H + W; i++) { ans += dp[H - 1][W - 1][i]; } cout << ans << endl; }