結果

問題 No.562 超高速一人かるた small
ユーザー koba-e964koba-e964
提出日時 2017-08-25 22:49:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,611 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 102,380 KB
実行使用メモリ 16,896 KB
最終ジャッジ日時 2024-04-23 16:10:07
合計ジャッジ時間 7,822 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, 0, n) {
    cin >> s[i];
    s[i] += '$';
  }
  vector<ll> dp(1 << n);
  dp[0] = 0;
  REP(bits, 1, 1 << n) {
    int k = __builtin_popcount(bits) - 1;
    ll fact = 1;
    REP(i, 0, k) {
      fact = fact * (i + 1) % mod;
    }
    ll tot = 0;
    vector<string> remaining;
    REP(i, 0, n) {
      if ((bits & 1 << i) == 0) {
	remaining.push_back(s[i]);
      }
    }
    REP(i, 0, n) {
      if ((bits & 1 << i) == 0) {
	continue;
      }
      int idx = 1;
      while (true) {
	bool ok = true;
	REP(j, 0, remaining.size()) {
	  if ((int) remaining[j].length() >= idx &&
	      remaining[j].substr(0, idx) == s[i].substr(0, idx)) {
	    ok = false;
	    break;
	  }
	}
	if (not ok) {
	  idx += 1;
	} else {
	  break;
	}
      }
      tot += dp[bits ^ 1 << i] + idx * fact % mod;
    }
    dp[bits] = tot % mod;
  }
  VL tbl(n + 1, 0);
  REP(bits, 0, 1 << n) {
    tbl[__builtin_popcount(bits)] += dp[bits];
  }
  REP(i, 1, n + 1) {
    cout << tbl[i] % mod << endl;
  }
}
0