結果

問題 No.562 超高速一人かるた small
ユーザー femtofemto
提出日時 2017-08-25 22:57:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 1,589 ms
コンパイル使用メモリ 165,624 KB
実行使用メモリ 20,044 KB
最終ジャッジ日時 2023-08-05 19:31:26
合計ジャッジ時間 11,597 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 79 ms
5,484 KB
testcase_09 WA -
testcase_10 AC 168 ms
11,560 KB
testcase_11 AC 355 ms
15,652 KB
testcase_12 AC 78 ms
5,620 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 758 ms
19,708 KB
testcase_15 AC 758 ms
19,712 KB
testcase_16 WA -
testcase_17 AC 758 ms
19,808 KB
testcase_18 AC 761 ms
19,712 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 759 ms
19,708 KB
testcase_22 WA -
testcase_23 AC 760 ms
19,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MOD = ll(1e9 + 7);
int N;
ll com[20][20];
ll dp[1 << 20];
ll cnt[1 << 20];
string s[20];
ll ans[22];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 0; i < N; i++) {
		cin >> s[i];
	}
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			if(i == j) continue;
			for(int k = 0; k < min(s[i].size(), s[j].size()); k++) {
				if(s[i][k] != s[j][k]) break;
				com[i][j]++;
			}
		}
	}

	cnt[0] = 1;
	for(int i = 0; i < 1 << N; i++) {
		int num = 0;
		for(int j = 0; j < N; j++) {
			if(i >> j & 1) num++;
		}
		for(int j = 0; j < N; j++) {
			if(i >> j & 1) continue;
			ll h = 1;
			for(int k = 0; k < N; k++) {
				if(i >> k & 1) continue;
				h = max(h, com[j][k] + 1);
			}
			dp[i | (1 << j)] += dp[i] + cnt[i] * h;
			dp[i | (1 << j)] % MOD;
			cnt[i | (1 << j)] += cnt[i];
			cnt[i | (1 << j)] % MOD;

			ans[num + 1] += dp[i] + cnt[i] * h;
			ans[num + 1] %= MOD;
		}
	}
	for(int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}
}
0