結果
問題 | No.118 門松列(2) |
ユーザー |
|
提出日時 | 2016-03-06 15:12:50 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 17 ms / 5,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 775 ms |
コンパイル使用メモリ | 71,112 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 08:09:19 |
合計ジャッジ時間 | 2,057 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#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; }