結果

問題 No.584 赤、緑、青の色塗り
ユーザー ats5515ats5515
提出日時 2017-10-27 23:14:47
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,744 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 94,320 KB
実行使用メモリ 186,652 KB
最終ジャッジ日時 2024-05-01 17:40:57
合計ジャッジ時間 6,798 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int myhash(int a, int b, int c) {
	return a * 1000000 + b * 1000 + c;
}
void unhash(int &a,int &b,int &c,int h) {
	c = h % 1000;
	h /= 1000;
	b = h % 1000;
	h /= 1000;
	a = h;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	N++;
	if (A + B + C - 3> (2.0 / 3.0)*N) {
		cout << 0 << endl;
		return 0;
	}


	vector<map<int, int> > dp(N + 1);
	dp[0][myhash(A, B, C)] = 1;
	int a, b, c;
	for (int i = 0; i < N; i++) {
		for (auto mp : dp[i]) {
			dp[i + 1][mp.first] = (dp[i + 1][mp.first] + mp.second) % MOD;
			unhash(a, b, c, mp.first);
		//	cerr << i << " " << a << " " << b << " " << c << " " << mp.second << endl;
			if (i + 2 <= N) {
				if (a > 0) {
					dp[i + 2][myhash(a - 1, b, c)] = (dp[i + 2][myhash(a - 1, b, c)] + mp.second) % MOD;
				}
				if (b > 0) {
					dp[i + 2][myhash(a, b - 1, c)] = (dp[i + 2][myhash(a, b - 1, c)] + mp.second) % MOD;
				}
				if (c > 0) {
					dp[i + 2][myhash(a, b, c - 1)] = (dp[i + 2][myhash(a, b, c - 1)] + mp.second) % MOD;
				}
			}
			if (i + 3 <= N) {
				if (a > 0 && b > 0) {
					dp[i + 3][myhash(a - 1, b - 1, c)] = (dp[i + 3][myhash(a - 1, b - 1, c)] + 2 * mp.second) % MOD;
				}
				if (b > 0 && c > 0) {
					dp[i + 3][myhash(a, b - 1, c - 1)] = (dp[i + 3][myhash(a, b - 1, c - 1)] + 2 * mp.second) % MOD;
				}
				if (c > 0 && a > 0) {
					dp[i + 3][myhash(a - 1, b, c - 1)] = (dp[i + 3][myhash(a - 1, b, c - 1)] + 2 * mp.second) % MOD;
				}
			}
		}
	}
	cout << dp[N][0] << endl;
}
0