結果

問題 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,578 ms
コンパイル使用メモリ 165,540 KB
実行使用メモリ 20,044 KB
最終ジャッジ日時 2024-04-23 16:11:10
合計ジャッジ時間 9,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 59 ms
5,504 KB
testcase_09 WA -
testcase_10 AC 125 ms
7,680 KB
testcase_11 AC 263 ms
11,776 KB
testcase_12 AC 62 ms
5,632 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 574 ms
19,968 KB
testcase_15 AC 583 ms
19,952 KB
testcase_16 WA -
testcase_17 AC 581 ms
19,840 KB
testcase_18 AC 570 ms
19,968 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 570 ms
19,860 KB
testcase_22 WA -
testcase_23 AC 581 ms
19,824 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