結果

問題 No.118 門松列(2)
ユーザー tsukiotsukio
提出日時 2016-03-06 15:12:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 852 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 70,480 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 14:09:01
合計ジャッジ時間 1,678 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 17 ms
5,376 KB
testcase_02 AC 15 ms
5,376 KB
testcase_03 AC 16 ms
5,376 KB
testcase_04 AC 17 ms
5,376 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 15 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 5 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 14 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 8 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
testcase_21 AC 12 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 12 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <unordered_map>
using namespace std;

long long CalcCombination(long long n, long long r) {
	long long divided = 1;
	long long divisor = 1;
	for (int i = 0; i < r; i++) {
		divided *= n - i;
		divisor *= r - i;
	}

	return divided / divisor;
}

int main() {
	int n;
	cin >> n;

	unordered_map<string, int> group_nums;
	string len;
	for (int i = 0; i < n; i++) {
		cin >> len;
		group_nums[len]++;
	}

	long long count_overlap = 0;
	for (auto pair : group_nums) {
		if (pair.second > 1) {
			count_overlap += CalcCombination(pair.second, 2) * CalcCombination(n - pair.second, 1);
			if (pair.second > 2) {
				count_overlap += CalcCombination(pair.second, 3);
			}
		}
	}

	long long total_combination = CalcCombination(n, 3) - count_overlap;
	cout << total_combination % 1000000007 << endl;

	return 0;
}
0