結果

問題 No.562 超高速一人かるた small
ユーザー ei1333333ei1333333
提出日時 2017-08-25 23:01:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 161,908 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-23 16:11:54
合計ジャッジ時間 10,329 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,648 KB
testcase_01 AC 7 ms
11,520 KB
testcase_02 AC 7 ms
11,648 KB
testcase_03 AC 6 ms
11,648 KB
testcase_04 AC 7 ms
11,520 KB
testcase_05 AC 7 ms
11,648 KB
testcase_06 AC 7 ms
11,648 KB
testcase_07 AC 10 ms
11,648 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 8 ms
11,520 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 #

#include<bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;

int N;
string S[20];
int dat[20][20];

int main()
{

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
    S[i] += "*";
  }

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      if(i == j) continue;

      int diff = 0;
      while(S[i][diff] == S[j][diff]) ++diff;
      dat[i][j] = diff + 1;
    }
  }

  int dp[1 << 20], comb[1 << 20];

  dp[0] = 0;
  comb[0] = 1;

  for(int i = 0; i < (1 << N); i++) {

    vector< int > yuki(N, 1);
    for(int j = 0; j < N; j++) {
      if(!((i >> j) & 1)) {
        for(int k = 0; k < N; k++) {
          if(!((i >> k) & 1)) yuki[j] = max(yuki[j], dat[j][k]);
        }
      }
    }

    for(int j = 0; j < N; j++) {
      if((i >> j) & 1) continue;
      (comb[i | (1 << j)] += comb[i]) %= mod;
      (dp[i | (1 << j)] += dp[i] + 1LL * yuki[j] * comb[i] % mod) %= mod;
    }
  }


  vector< int > ans(N, 0);
  for(int i = 0; i < (1 << N); i++) {
    (ans[__builtin_popcount(i) - 1] += 1LL * dp[i] % mod) %= mod;
  }
  for(int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
}
0