結果

問題 No.563 超高速一人かるた large
ユーザー 37zigen37zigen
提出日時 2017-08-26 12:54:02
言語 Java21
(openjdk 21)
結果
AC  
実行時間 759 ms / 3,000 ms
コード長 2,000 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 78,696 KB
実行使用メモリ 130,664 KB
最終ジャッジ日時 2024-04-23 17:08:13
合計ジャッジ時間 12,755 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
86,064 KB
testcase_01 AC 176 ms
85,628 KB
testcase_02 AC 178 ms
86,200 KB
testcase_03 AC 224 ms
86,552 KB
testcase_04 AC 239 ms
86,296 KB
testcase_05 AC 251 ms
85,860 KB
testcase_06 AC 390 ms
91,208 KB
testcase_07 AC 445 ms
93,528 KB
testcase_08 AC 589 ms
114,432 KB
testcase_09 AC 759 ms
129,068 KB
testcase_10 AC 616 ms
129,004 KB
testcase_11 AC 678 ms
130,308 KB
testcase_12 AC 662 ms
129,444 KB
testcase_13 AC 651 ms
129,572 KB
testcase_14 AC 691 ms
129,464 KB
testcase_15 AC 657 ms
130,264 KB
testcase_16 AC 722 ms
130,664 KB
testcase_17 AC 403 ms
89,448 KB
testcase_18 AC 704 ms
128,444 KB
testcase_19 AC 253 ms
84,800 KB
testcase_20 AC 535 ms
114,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MODULO = 1_000_000_000 + 7;
	long[] fac = new long[2001];
	{
		fac[0] = 1;
		for (int i = 1; i < fac.length; ++i) {
			fac[i] = fac[i - 1] * i % MODULO;
		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		for (int i = 0; i < n; ++i) {
			s[i] = sc.next();
		}
		Arrays.sort(s);
		long[][] f = new long[n][n];
		for (int i = 0; i < n; ++i) {
			f[i][i] = s[i].length();
			if (i + 1 < n) {
				int L = 0;
				while (L < Math.min(s[i].length(), s[i + 1].length()) && s[i].charAt(L) == s[i + 1].charAt(L)) {
					++L;
				}
				f[i][i + 1] = L;
				f[i + 1][i] = L;
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = i + 2; j < n; ++j) {
				f[i][j] = Math.min(f[j - 1][j], f[i][j - 1]);
				f[j][i] = f[i][j];
			}
		}
		long[][] comb = new long[2001][2001];
		comb[0][0] = 1;
		for (int i = 1; i <= 2000; ++i) {
			for (int j = 0; j <= i; ++j) {
				comb[i][j] = (j > 0 ? comb[i - 1][j - 1] : 0) + comb[i - 1][j];
				comb[i][j] %= MODULO;
			}
		}
		long[] dp = new long[n + 1];
		for (int a = 0; a < n; ++a) {
			for (int b = a + 1; b < n; ++b) {
				dp[b - a] += Math.max(f[a][b], b + 1 < n ? f[b][b + 1] : 0) + 1;
				dp[b - a] %= MODULO;
			}
		}

		long[] ans = new long[n + 1];
		for (int b = 0; b < n; ++b) {
			for (int K = b + 1; K <= n; ++K) {
				ans[K] += ((b + 1 < n ? f[b][b + 1] : 0) + 1) * comb[n - (b + 1)][K - (b + 1)] % MODULO * fac[K]
						% MODULO;
				ans[K] %= MODULO;
			}
		}
		for (int K = 1; K <= n; ++K) {
			for (int d = 1; d <= K && n - d - 1 >= 0; ++d) {
				ans[K] += comb[n - d - 1][K - d] * dp[d] % MODULO * fac[K] % MODULO;
				ans[K] %= MODULO;
			}
		}
		for(int K=1;K<=n;++K){
			System.out.println(ans[K]);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0