結果

問題 No.2708 Jewel holder
ユーザー startcppstartcpp
提出日時 2024-03-31 14:08:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 85,348 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 14:08:21
合計ジャッジ時間 1,493 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//全探索でも解けるんですが、実装の練習としてDPで解いてみます。
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int h, w;
string s[10];
int dp[10][10][21];

signed main() {
	int i, j, k;
	cin >> h >> w;
	rep(i, h) cin >> s[i];
	
	dp[0][0][1] = 1;
	rep(i, h) {
		rep(j, w) {
			rep(k, 21) {
				if (i + 1 < h && s[i + 1][j] != '#' && (k > 0 || s[i + 1][j] != 'x')) {
					int nk;
					if (s[i + 1][j] == 'o') nk = k + 1;
					else if (s[i + 1][j] == 'x') nk = k - 1;
					else nk = k;
					dp[i + 1][j][nk] += dp[i][j][k];
				}
				if (j + 1 < w && s[i][j + 1] != '#' && (k > 0 || s[i][j + 1] != 'x')) {
					int nk;
					if (s[i][j + 1] == 'o') nk = k + 1;
					else if (s[i][j + 1] == 'x') nk = k - 1;
					else nk = k;
					dp[i][j + 1][nk] += dp[i][j][k];
				}
			}
		}
	}

	int ans = 0;
	rep(k, 21) ans += dp[h - 1][w - 1][k];
	
	cout << ans << endl;
	return 0;
}
0