結果

問題 No.314 ケンケンパ
ユーザー cielciel
提出日時 2015-12-07 00:25:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 679 ms / 1,000 ms
コード長 1,024 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 60,836 KB
実行使用メモリ 256,860 KB
最終ジャッジ日時 2023-10-12 18:38:46
合計ジャッジ時間 3,858 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 667 ms
256,120 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 5 ms
4,352 KB
testcase_15 AC 8 ms
4,884 KB
testcase_16 AC 19 ms
8,148 KB
testcase_17 AC 67 ms
24,020 KB
testcase_18 AC 295 ms
103,672 KB
testcase_19 AC 679 ms
256,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <unordered_map>
#include <cstdio>
using namespace std;

namespace std{
	template<typename T>
	inline void hash_combine(size_t& seed, T const& v){
		seed ^= hash<T>()(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
	}
	template<typename It>
	inline size_t hash_range(It first, It last){
		size_t seed=0;
		hash_range(seed,first,last);
		return seed;
	}
	template<typename It>
	inline void hash_range(size_t& seed, It first, It last){
		for(;first!=last;++first)hash_combine(seed, *first);
	}
	template<typename A,typename B>
	class hash<pair<A,B>>{
		public:
		size_t operator()(pair<A,B> const &p) const{
			size_t seed=0;
			hash_combine(seed,p.first);
			hash_combine(seed,p.second);
			return seed;
		}
	};
}

unordered_map<pair<int,int>,int>memo;
int dfs(int k,int p,int d){
	if(k<0||p<0)return 0;
	if(d==0)return 1;
	auto x=make_pair(k*2+p,d);
	if(memo.find(x)==memo.end()){
		memo[x]=(dfs(k-1,1,d-1)+dfs(2,p-1,d-1))%1000000007;
	}
	return memo[x];
}
int main(){
	int n;
	scanf("%d",&n);
	printf("%d\n",dfs(2,0,n));
}
0