結果

問題 No.562 超高速一人かるた small
ユーザー yukudoyukudo
提出日時 2017-08-25 23:45:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 542 ms / 3,000 ms
コード長 1,642 bytes
コンパイル時間 1,958 ms
コンパイル使用メモリ 163,100 KB
実行使用メモリ 11,724 KB
最終ジャッジ日時 2024-04-23 16:18:09
合計ジャッジ時間 9,006 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,648 KB
testcase_01 AC 6 ms
11,484 KB
testcase_02 AC 6 ms
11,648 KB
testcase_03 AC 6 ms
11,648 KB
testcase_04 AC 7 ms
11,648 KB
testcase_05 AC 7 ms
11,724 KB
testcase_06 AC 6 ms
11,640 KB
testcase_07 AC 8 ms
11,648 KB
testcase_08 AC 62 ms
11,648 KB
testcase_09 AC 542 ms
11,580 KB
testcase_10 AC 125 ms
11,392 KB
testcase_11 AC 256 ms
11,648 KB
testcase_12 AC 60 ms
11,500 KB
testcase_13 AC 7 ms
11,648 KB
testcase_14 AC 537 ms
11,636 KB
testcase_15 AC 538 ms
11,612 KB
testcase_16 AC 540 ms
11,648 KB
testcase_17 AC 536 ms
11,648 KB
testcase_18 AC 537 ms
11,648 KB
testcase_19 AC 534 ms
11,708 KB
testcase_20 AC 539 ms
11,608 KB
testcase_21 AC 541 ms
11,552 KB
testcase_22 AC 538 ms
11,372 KB
testcase_23 AC 538 ms
11,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}

const ll MOD = 1000000007;

const int MAX_N = 20;
string s[MAX_N];
int diff[MAX_N][MAX_N];
ll dp[1 << MAX_N];
ll fact[MAX_N + 10];

int main2() {
  int N; cin >> N;
  fact[0] = 1;
  for (int i = 1; i <= N; i++) fact[i] = (fact[i-1] * i) % MOD;
  REP(i, N) { cin >> s[i]; s[i] += "$"; }
  REP(i, N) REP(j, N) {
    int d = 0;
    if (i == j) 
      d = 1;
    else {
      while (s[i][d] == s[j][d]) d++;
      d++;
    }
    diff[i][j] = d;
  }
  memset(dp, 0, sizeof(dp));

  for (int s = 0; s < (1 << N); s++) {
    int on = __builtin_popcount(s);
    REP(k, N) if ((s >> k & 1) == 0) {
      int cost = 0;
      REP(j, N) if ((s >> j & 1) == 0) {
        chmax(cost, diff[k][j]);
      }
      // if (N == 3) {
        // cout << bitset<3>(s) << " " << dp[s] << " k=" << k << " " << cost << endl;
      // }
      (dp[s | (1 << k)] += dp[s] + cost * fact[on]) %= MOD;
    }
  }

  vector<ll> ans(N+1);
  for (int s = 0; s < (1 << N); s++) {
    (ans[__builtin_popcount(s)] += dp[s]) %= MOD;
  }
  for (int i = 1; i <= N; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

0