結果

問題 No.562 超高速一人かるた small
ユーザー pekempeypekempey
提出日時 2017-08-25 22:54:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 798 ms / 3,000 ms
コード長 1,191 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 83,928 KB
実行使用メモリ 19,768 KB
最終ジャッジ日時 2023-08-05 19:30:36
合計ジャッジ時間 11,423 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 81 ms
5,184 KB
testcase_09 AC 790 ms
19,544 KB
testcase_10 AC 171 ms
7,348 KB
testcase_11 AC 370 ms
11,380 KB
testcase_12 AC 82 ms
5,248 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 796 ms
19,536 KB
testcase_15 AC 798 ms
19,448 KB
testcase_16 AC 792 ms
19,544 KB
testcase_17 AC 790 ms
19,768 KB
testcase_18 AC 792 ms
19,648 KB
testcase_19 AC 794 ms
19,644 KB
testcase_20 AC 795 ms
19,540 KB
testcase_21 AC 792 ms
19,556 KB
testcase_22 AC 794 ms
19,536 KB
testcase_23 AC 796 ms
19,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

constexpr long long mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;

  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  vector<vector<int>> lcp(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int k = 0;
      while (k < s[i].size() && k < s[j].size() && s[i][k] == s[j][k]) k++;
      lcp[i][j] = k;
    }
  }

  vector<long long> dp(1 << n);
  vector<long long> way(1 << n);
  way[0] = 1;
  for (int i = 0; i < 1 << n; i++) {
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) continue;
      int l = 0;
      for (int k = 0; k < n; k++) {
        if (j == k) continue;
        if (~i >> k & 1) {
          l = max(l, lcp[j][k]);
        }
      }
      (dp[i | 1 << j] += dp[i] + (l + 1) * way[i]) %= mod;
      (way[i | 1 << j] += way[i]) %= mod;
    }
  }

  vector<long long> ans(n + 1);
  for (int i = 0; i < 1 << n; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      cnt += i >> j & 1;
    }
    ans[cnt] += dp[i];
  }

  for (int i = 1; i <= n; i++) {
    cout << ans[i] % mod << endl;
  }
}
0