結果
| 問題 |
No.562 超高速一人かるた small
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-26 18:14:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 814 ms / 3,000 ms |
| コード長 | 2,432 bytes |
| コンパイル時間 | 1,839 ms |
| コンパイル使用メモリ | 181,252 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 17:47:31 |
| 合計ジャッジ時間 | 12,322 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
// {{{ Templates
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
os << "sz:" << v.size() << "\n[";
for (const auto& p : v) {
os << p << ",";
}
os << "]\n";
return os;
}
template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
os << "(" << p.first << "," << p.second
<< ")";
return os;
}
constexpr ll MOD = (ll)1e9 + 7LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;
// }}}
struct Graph {
Graph(const ll n)
{
edge.resize(n, vector<ll>(n));
}
void addEdge(const ll from, const ll to, const ll cost)
{
edge[from][to] = cost;
edge[to][from] = cost;
}
vector<vector<ll>> edge;
};
inline ll common(const string& s1, const string& s2)
{
ll c = 0;
for (ll i = 0; i < min(s1.size(), s2.size()); i++) {
if (s1[i] == s2[i]) {
c++;
} else {
break;
}
}
return c + 1;
}
ll frac(const ll n)
{
ll ans = 1;
for (ll i = 1; i <= n; i++) {
ans = (ans * i) % MOD;
}
return ans;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
const ll maximum = 1 << N;
vector<string> S(N);
Graph g(N);
for (ll i = 0; i < N; i++) {
cin >> S[i];
}
for (ll i = 0; i < N; i++) {
for (ll j = i + 1; j < N; j++) {
g.addEdge(i, j, common(S[i], S[j]));
}
}
vector<ll> costs(N);
for (ll i = 1; i < maximum; i++) {
vector<bool> used(N, false);
ll num = i;
ll cost = 0;
ll pop = 0;
for (ll d = 0; d < N; d++) {
if (num % 2 == 1) {
pop++;
ll maxi = 1;
for (ll j = 0; j < N; j++) {
if (not used[j]) {
maxi = max(maxi, g.edge[d][j]);
}
}
cost = (cost + maxi) % MOD;
used[d] = true;
}
num /= 2;
}
costs[pop - 1] = (costs[pop - 1] + cost) % MOD;
}
for (int i = 0; i < N; i++) {
cout << (frac(i + 1) * costs[i]) % MOD << endl;
}
return 0;
}