結果

問題 No.562 超高速一人かるた small
ユーザー ikdikd
提出日時 2017-08-26 03:44:20
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 1,051 ms / 3,000 ms
コード長 1,070 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 90,316 KB
実行使用メモリ 13,324 KB
最終ジャッジ日時 2023-09-03 16:07:45
合計ジャッジ時間 14,205 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 113 ms
4,656 KB
testcase_09 AC 1,045 ms
12,328 KB
testcase_10 AC 239 ms
6,732 KB
testcase_11 AC 502 ms
8,508 KB
testcase_12 AC 115 ms
5,868 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 1,045 ms
12,076 KB
testcase_15 AC 1,051 ms
12,260 KB
testcase_16 AC 1,036 ms
12,064 KB
testcase_17 AC 1,046 ms
13,052 KB
testcase_18 AC 1,044 ms
12,064 KB
testcase_19 AC 1,050 ms
12,532 KB
testcase_20 AC 1,047 ms
13,324 KB
testcase_21 AC 1,050 ms
12,320 KB
testcase_22 AC 1,045 ms
11,784 KB
testcase_23 AC 1,050 ms
12,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.range;

  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; i..n){
    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); // 0->remaining, 1->used
  foreach(i; 0..(1<<n)){
    int[] v;
    foreach(j; 0..n){
      if(!(i>>j&1)) v~=j;
    }
    foreach(k; 0..v.length){
      auto c=0;
      if(k>0) c=max(c, mm[v[k-1]][v[k]]);
      if(k+1<v.length) c=max(c, mm[v[k]][v[k+1]]);
      (dp[i|(1<<v[k])]+=dp[i]+(c+1)*f[n-v.length])%=mod;
    }
    (ex[n-v.length]+=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