結果

問題 No.562 超高速一人かるた small
ユーザー femtofemto
提出日時 2017-08-25 22:56:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,062 bytes
コンパイル時間 1,646 ms
コンパイル使用メモリ 164,480 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-04-23 16:11:00
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 61 ms
5,504 KB
testcase_09 WA -
testcase_10 AC 132 ms
7,552 KB
testcase_11 AC 276 ms
11,776 KB
testcase_12 AC 61 ms
5,632 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 585 ms
19,892 KB
testcase_15 AC 593 ms
19,968 KB
testcase_16 WA -
testcase_17 AC 582 ms
19,840 KB
testcase_18 AC 584 ms
20,056 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 590 ms
19,884 KB
testcase_22 WA -
testcase_23 AC 586 ms
19,968 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 = 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