結果

問題 No.562 超高速一人かるた small
ユーザー latte0119latte0119
提出日時 2017-08-25 22:47:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 821 ms / 3,000 ms
コード長 1,734 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 160,400 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-23 16:09:59
合計ジャッジ時間 11,700 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,912 KB
testcase_01 AC 6 ms
6,912 KB
testcase_02 AC 6 ms
6,912 KB
testcase_03 AC 6 ms
6,912 KB
testcase_04 AC 6 ms
7,040 KB
testcase_05 AC 6 ms
6,912 KB
testcase_06 AC 5 ms
6,912 KB
testcase_07 AC 9 ms
7,040 KB
testcase_08 AC 85 ms
7,936 KB
testcase_09 AC 792 ms
15,104 KB
testcase_10 AC 172 ms
8,960 KB
testcase_11 AC 370 ms
11,008 KB
testcase_12 AC 85 ms
7,808 KB
testcase_13 AC 8 ms
7,040 KB
testcase_14 AC 799 ms
15,104 KB
testcase_15 AC 788 ms
15,104 KB
testcase_16 AC 803 ms
15,104 KB
testcase_17 AC 795 ms
15,004 KB
testcase_18 AC 810 ms
15,104 KB
testcase_19 AC 821 ms
15,092 KB
testcase_20 AC 802 ms
14,976 KB
testcase_21 AC 800 ms
14,976 KB
testcase_22 AC 805 ms
15,104 KB
testcase_23 AC 810 ms
14,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
int fact[222222];
int inv[222222];

int P(int n,int k){
    return fact[n]*inv[n-k];
}

int N;
int dp[1<<20];

string S[22];
int L[22][22];
signed main(){
    fact[0]=1;
    for(int i=1;i<222222;i++)fact[i]=fact[i-1]*i%mod;
    inv[222222-1]=mpow(fact[222222-1],mod-2);
    for(int i=222222-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;

    cin>>N;
    rep(i,N)cin>>S[i];

    rep(i,N){
        rep(j,N){
            if(i==j)continue;
            for(int k=0;;k++){
                if(S[i].size()==k||S[j].size()==k||S[i][k]!=S[j][k]){
                    L[i][j]=k+1;
                    break;
                }
            }
        }
    }

    int ans[22]={};

    dp[0]=0;
    rep(i,1<<N){
        int cnt=0;
        rep(j,N)if(i>>j&1)cnt++;
        rep(j,N){
            if(i>>j&1)continue;
            int cost=1;
            rep(k,N){
                if(i>>k&1)continue;
                if(j==k)continue;
                chmax(cost,L[j][k]);
            }
            dp[i|(1<<j)]=(dp[i|(1<<j)]+dp[i]+cost*fact[cnt])%mod;
        }
        ans[cnt]=(ans[cnt]+dp[i])%mod;
    }

    for(int i=1;i<=N;i++)cout<<ans[i]<<endl;
    return 0;
}
0