結果

問題 No.73 helloworld
ユーザー kongarishisyamokongarishisyamo
提出日時 2016-03-18 13:36:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,048 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 52,656 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-11 23:53:49
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>

#define N 100
long long comb[N + 1][N + 1];

using namespace std;

int main(){

	for (int i = 0; i <= N; i++){
		comb[i][0] = 1;
		for (int j = 1; j <= i; j++){
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1]; 
		}
	}

	int C['z' - 'a' + 1];
	char hw[] = { 'h', 'e', 'l', 'o', 'w', 'r', 'd', -1 };
	int c[] = { 1, 1, 3, 2, 1, 1, 1, -1 };
	int c2[] = { 1, 1, 2, 1, 1, 1, 1 };
	for (int i = 'a'; i <= 'z'; i++){
		cin >> C[i - 'a'];
	}

	long long ans = 1;
	for (int i = 0; c[i] != -1; i++){
		if (C[hw[i] - 'a'] - c[i] < 0){
			ans = 0;
			break;
		}
		if (c[i] == c2[i]){
			ans *= comb[C[hw[i] - 'a']][c2[i]];
		}
		else{
			long long t2 = c[i] - c2[i];
			long long t1 = C[hw[i] - 'a'] - t2;
			long long max = -1;
			//cout << t1 << "," << t2 << endl;
			while (t1 >= c2[i]){
				//cout << comb[t1][c2[i]] << "|" << comb[t2][c[i] - c2[i]] << endl;
				if (max<comb[t1][c2[i]] * comb[t2][c[i] - c2[i]]) max = comb[t1][c2[i]] * comb[t2][c[i] - c2[i]];
				t1--;
				t2++;
			}
			ans *= max;
		}
	}

	cout << ans << endl;
}
0