結果

問題 No.562 超高速一人かるた small
ユーザー tsutajtsutaj
提出日時 2017-08-25 23:52:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 570 ms / 3,000 ms
コード長 2,314 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 102,900 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2024-04-23 16:19:56
合計ジャッジ時間 8,228 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 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 4 ms
5,376 KB
testcase_08 AC 58 ms
5,760 KB
testcase_09 AC 554 ms
19,920 KB
testcase_10 AC 122 ms
7,680 KB
testcase_11 AC 261 ms
11,776 KB
testcase_12 AC 58 ms
5,632 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 561 ms
19,968 KB
testcase_15 AC 554 ms
19,840 KB
testcase_16 AC 570 ms
20,044 KB
testcase_17 AC 559 ms
19,968 KB
testcase_18 AC 561 ms
19,924 KB
testcase_19 AC 565 ms
19,920 KB
testcase_20 AC 566 ms
19,968 KB
testcase_21 AC 568 ms
19,920 KB
testcase_22 AC 557 ms
19,968 KB
testcase_23 AC 558 ms
20,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int diff[25][25];
int dp[1 << 20], enumerate[1 << 20], rec[25];
int N;
vector<string> vs;

signed main() {
    cin >> N;
    rep(i,0,N) {
        string s; cin >> s;
        vs.push_back(s);
    }

    rep(i,0,N) rep(j,i+1,N) {
        int idx = 0, ans = -1;
        while(idx < vs[i].length() && idx < vs[j].length()) {
            if(vs[i][idx] != vs[j][idx]) {
                ans = idx;
                break;
            }
            else idx++;
        }
        if(ans < 0) ans = min(vs[i].length(), vs[j].length());
        diff[i][j] = diff[j][i] = ans + 1;
    }

    /*
    rep(i,0,N) {
        rep(j,0,N) printf("%lld ", diff[i][j]);
        cout << endl;
    }
    */

    enumerate[(1 << N) - 1] = 1;
    repr(bit,(1<<N)-1,0) {
        rep(i,0,N) if(bit >> i & 1) {
            int ma = 1;
            rep(j,0,N) if(bit >> j & 1) chmax(ma, diff[i][j]);
            int nbit = bit ^ (1 << i);
            (enumerate[nbit] += enumerate[bit]) %= MOD;
            (dp[nbit] += (dp[bit] + enumerate[bit] * ma) % MOD) %= MOD;
        }
    }

    // rep(i,0,1<<N) printf("dp[%lld] = %lld, enum = %lld\n", i, dp[i], enumerate[i]);

    rep(bit,0,1<<N) {
        int cnt = __builtin_popcount(bit);
        (rec[cnt] += dp[bit]) %= MOD;
    }
    repr(i,N-1,0) cout << rec[i] << endl;
    return 0;
}
0