結果
問題 | No.562 超高速一人かるた small |
ユーザー |
![]() |
提出日時 | 2017-08-26 03:56:08 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,127 ms / 3,000 ms |
コード長 | 987 bytes |
コンパイル時間 | 957 ms |
コンパイル使用メモリ | 105,436 KB |
実行使用メモリ | 11,628 KB |
最終ジャッジ日時 | 2024-06-12 21:48:14 |
合計ジャッジ時間 | 14,076 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
void main(){import std.stdio, std.string, std.conv, std.algorithm;int n; rd(n);auto ss=new string[](n);foreach(i; 0..n) rd(ss[i]);sort(ss);auto mm=new int[][](n, n);foreach(i; 0..n)foreach(j; 0..i){int k=0;while(k<ss[i].length && k<ss[j].length&& ss[i][k]==ss[j][k]) k++;mm[i][j]=mm[j][i]=k;}long mod=10^^9+7;auto f=new long[](n+1); f[0]=1;foreach(i; 1..f.length) f[i]=i*f[i-1]%mod;auto ex=new long[](n+1);auto dp=new long[](1<<n); // 1->remaining, 0->usedforeach_reverse(i; 0..(1<<n)){auto m=0;foreach(j; 0..n)if(i>>j&1) m++;foreach(j; 0..n)if(i>>j&1){auto c=0;foreach(k; 0..n)if(i>>k&1) c=max(c, mm[j][k]);(dp[i^(1<<j)]+=dp[i]+(c+1)*f[n-m])%=mod;}(ex[n-m]+=dp[i])%=mod;}foreach(k; 1..ex.length) writeln(ex[k]);}void rd(T...)(ref T x){import std.stdio, std.string, std.conv;auto l=readln.split;foreach(i, ref e; x){e=l[i].to!(typeof(e));}}