結果
| 問題 |
No.562 超高速一人かるた small
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-26 00:19:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,031 bytes |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 71,204 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-15 16:53:02 |
| 合計ジャッジ時間 | 4,784 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 3 |
| other | RE * 21 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lint;
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MOD ((lint)1000000007)
template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
if (v.empty()) {
cout << "{ }";
return ostr;
}
cout << "{" << v.front();
for (auto itr = ++v.begin(); itr != v.end(); itr++) {
cout << ", " << *itr;
}
cout << "}";
return ostr;
}
/*
6
abc
abcedaa
abcdefg
abvdegf
aaa
abceg
*/
lint ipow(lint x, lint n)
{
lint i, ret = 1;
for (i = 0; i<n; i++)
ret *= x;
return ret;
}
lint Combination(lint n, lint r)
{
lint i, ret = 1;
r = MIN(n - r, r);
for (i = 1; i <= r; i++) {
ret = ret * (n - i + 1) / i;
}
return ret % MOD;
}
lint common_seq(const string& a, const string& b)
{
lint i;
for (i = 0; i < MIN(a.size(), b.size()); i++) {
if (a[i] != b[i]) break;
}
return i;
}
//bits : 残っているかるた
lint fatigue(vector<string>& S, lint bits, lint N)
{
lint fatigue = 0;
vector<string> sub;
for (int i = 0; bits != 0, i < N; i++) {
if (bits % 2) sub.push_back(S[i]);
bits /= 2;
}
if (sub.size() == 1) fatigue = 1;
else {
fatigue += common_seq(sub[0], sub[1]) + 1;
for (lint i = 1; i < sub.size() - 1; i++) {
fatigue += MAX(common_seq(sub[i - 1], sub[i]), common_seq(sub[i], sub[i + 1])) + 1;
}
if (sub.size() != 2) {
fatigue += common_seq(sub[sub.size() - 2], sub[sub.size() - 1]) + 1;
}
}
lint prob = Combination(N, sub.size()) * fatigue % MOD;
return prob;
}
int main()
{
lint N, pw, E[21] = { 0 };
cin >> N;
vector<string> S(N);
for (lint i = 0; i < N; i++) {
cin >> S[i];
//S[i].push_back('0');
}
sort(S.begin(), S.end());
//cout << S << endl;
pw = ipow(2, N);
for (int b = 0; b < pw; b++) {
lint nb = 0;
for (int i = 1; i <= (1 << 20); i <<= 1) {
if (b & 1) nb++;
}
E[nb] += fatigue(S, b, N);
E[nb] %= MOD;
}
for (int i = 0; i < N; i++)
cout << E[i] << endl;
return 0;
}