結果

問題 No.2708 Jewel holder
ユーザー ku_senjan
提出日時 2024-03-31 13:46:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 1,781 ms
コンパイル使用メモリ 205,484 KB
最終ジャッジ日時 2025-02-20 16:33:27
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
template<class T> using graph=vector<vector<T>>;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
constexpr int INF32=INT_MAX/2;
constexpr ll INF64=1LL<<60;
constexpr array<int,4> DX4={0,1,0,-1};
constexpr array<int,4> DY4={-1,0,1,0};
constexpr array<int,8> DX8={0,1,1,1,0,-1,-1,-1};
constexpr array<int,8> DY8={-1,-1,0,1,1,1,0,-1};
inline int popcnt(ll n){return __builtin_popcountll(n);}
template<class T> inline bool chmax(T& a,const T& b){return a<b?a=b,true:false;}
template<class T> inline bool chmin(T& a,const T& b){return b<a?a=b,true:false;}
#define rep(i,s,n) for(ll i=(ll)(s);i<(ll)(n);i++)
#define rrep(i,s,n) for(ll i=(ll)(s);i>=(ll)(n);i--)
void _main();
int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(16);
	_main();
}

void _main(){
	int H, W; cin >> H >> W;
	vector<string> S(H); rep(i,0,H) cin >> S[i];

	vector dp(H, vector(W, vector<ll>(H+W)));
	dp[0][0][1] = 1;
	rep(i,0,H) rep(j,0,W) if(S[i][j]!='#'){
		rep(k,0,H+W){
			if(i+1<H){
				if(S[i+1][j]=='o'){
					if(k+1<H+W) dp[i+1][j][k+1] += dp[i][j][k];
				}else if(S[i+1][j]=='x'){
					if(k-1>=0) dp[i+1][j][k-1] += dp[i][j][k];
				}
			}
			if(j+1<W){
				if(S[i][j+1]=='o'){
					if(k+1<H+W) dp[i][j+1][k+1] += dp[i][j][k];
				}else if(S[i][j+1]=='x'){
					if(k-1>=0) dp[i][j+1][k-1] += dp[i][j][k];
				}
			}
		}
	}

	ll ans = 0;
	rep(i,0,H+W){
		ans += dp[H-1][W-1][i];
	}
	cout << ans << endl;
}
0