結果

問題 No.562 超高速一人かるた small
ユーザー ikdikd
提出日時 2017-08-26 03:38:49
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,153 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 90,360 KB
実行使用メモリ 13,684 KB
最終ジャッジ日時 2023-09-03 16:07:05
合計ジャッジ時間 13,325 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,384 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 4 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

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]);

  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;

  sort(ss); 
  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;
  }
  
  /*
  000 001 010 011 100 101 110 111
    0   3   3   8   1   8   8   30
  */

  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