結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 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,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 62 ms
5,436 KB
testcase_09 WA -
testcase_10 AC 134 ms
11,536 KB
testcase_11 AC 283 ms
15,664 KB
testcase_12 AC 63 ms
5,440 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 598 ms
19,816 KB
testcase_15 AC 598 ms
19,756 KB
testcase_16 WA -
testcase_17 AC 598 ms
19,868 KB
testcase_18 AC 600 ms
19,740 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 598 ms
19,936 KB
testcase_22 WA -
testcase_23 AC 600 ms
19,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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;
			int h = 0;
			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