結果
| 問題 |
No.562 超高速一人かるた small
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-08-25 22:49:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,611 bytes |
| コンパイル時間 | 1,120 ms |
| コンパイル使用メモリ | 103,304 KB |
| 実行使用メモリ | 16,640 KB |
| 最終ジャッジ日時 | 2024-10-15 16:37:29 |
| 合計ジャッジ時間 | 7,912 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 -- * 1 |
| other | AC * 7 TLE * 1 -- * 13 |
ソースコード
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
int main(void) {
int n;
cin >> n;
vector<string> s(n);
REP(i, 0, n) {
cin >> s[i];
s[i] += '$';
}
vector<ll> dp(1 << n);
dp[0] = 0;
REP(bits, 1, 1 << n) {
int k = __builtin_popcount(bits) - 1;
ll fact = 1;
REP(i, 0, k) {
fact = fact * (i + 1) % mod;
}
ll tot = 0;
vector<string> remaining;
REP(i, 0, n) {
if ((bits & 1 << i) == 0) {
remaining.push_back(s[i]);
}
}
REP(i, 0, n) {
if ((bits & 1 << i) == 0) {
continue;
}
int idx = 1;
while (true) {
bool ok = true;
REP(j, 0, remaining.size()) {
if ((int) remaining[j].length() >= idx &&
remaining[j].substr(0, idx) == s[i].substr(0, idx)) {
ok = false;
break;
}
}
if (not ok) {
idx += 1;
} else {
break;
}
}
tot += dp[bits ^ 1 << i] + idx * fact % mod;
}
dp[bits] = tot % mod;
}
VL tbl(n + 1, 0);
REP(bits, 0, 1 << n) {
tbl[__builtin_popcount(bits)] += dp[bits];
}
REP(i, 1, n + 1) {
cout << tbl[i] % mod << endl;
}
}