結果

問題 No.562 超高速一人かるた small
ユーザー ikdikd
提出日時 2017-08-26 03:56:08
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,106 ms / 3,000 ms
コード長 987 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 90,244 KB
実行使用メモリ 12,008 KB
最終ジャッジ日時 2023-09-03 16:08:16
合計ジャッジ時間 15,608 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 115 ms
4,380 KB
testcase_09 AC 1,008 ms
9,864 KB
testcase_10 AC 235 ms
4,880 KB
testcase_11 AC 509 ms
7,656 KB
testcase_12 AC 105 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 1,069 ms
11,272 KB
testcase_15 AC 1,059 ms
9,920 KB
testcase_16 AC 1,106 ms
9,920 KB
testcase_17 AC 1,028 ms
11,548 KB
testcase_18 AC 1,049 ms
12,008 KB
testcase_19 AC 1,022 ms
11,552 KB
testcase_20 AC 1,022 ms
10,948 KB
testcase_21 AC 1,037 ms
9,944 KB
testcase_22 AC 1,102 ms
11,288 KB
testcase_23 AC 1,052 ms
11,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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->used
  foreach_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));
  }
}
0