結果

問題 No.562 超高速一人かるた small
ユーザー finefine
提出日時 2017-08-26 01:34:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 532 ms / 3,000 ms
コード長 1,053 bytes
コンパイル時間 1,602 ms
コンパイル使用メモリ 167,008 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-23 16:32:12
合計ジャッジ時間 8,616 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 56 ms
6,940 KB
testcase_09 AC 516 ms
11,648 KB
testcase_10 AC 113 ms
6,940 KB
testcase_11 AC 239 ms
7,424 KB
testcase_12 AC 54 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 518 ms
11,776 KB
testcase_15 AC 514 ms
11,648 KB
testcase_16 AC 510 ms
11,648 KB
testcase_17 AC 521 ms
11,648 KB
testcase_18 AC 529 ms
11,648 KB
testcase_19 AC 526 ms
11,520 KB
testcase_20 AC 523 ms
11,776 KB
testcase_21 AC 532 ms
11,648 KB
testcase_22 AC 520 ms
11,520 KB
testcase_23 AC 516 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

ll cost[20][20], fact[20];
ll dp[1 << 20], ans[21];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			cost[i][j] = 1;
			for (int k = 0; k < min(s[i].length(), s[j].length()); k++) {
				if (s[i][k] != s[j][k]) break;
				cost[i][j]++;
			}
			cost[j][i] = cost[i][j];
		}
	}

	fact[0] = 1;
	for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;;

	for (int i = (1 << n) - 1; i >= 0; i--) {
		int cnt = n - __builtin_popcount(i);
		(ans[cnt] += dp[i]) %= MOD;
		ll tmp = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				ll tmp = 1;
				for (int k = 0; k < n; k++) {
					if (i & (1 << k)) tmp = max(tmp, cost[k][j]);
				}
				(dp[i ^ (1 << j)] += dp[i] + fact[cnt] * tmp % MOD) %= MOD;
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}
0