結果

問題 No.562 超高速一人かるた small
ユーザー SugarDragon5SugarDragon5
提出日時 2017-08-26 08:33:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,410 ms / 3,000 ms
コード長 1,398 bytes
コンパイル時間 2,016 ms
コンパイル使用メモリ 169,856 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-23 17:01:57
合計ジャッジ時間 19,828 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 135 ms
5,376 KB
testcase_09 AC 1,392 ms
11,776 KB
testcase_10 AC 294 ms
5,632 KB
testcase_11 AC 650 ms
7,680 KB
testcase_12 AC 135 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 1,395 ms
11,776 KB
testcase_15 AC 1,395 ms
11,648 KB
testcase_16 AC 1,410 ms
11,776 KB
testcase_17 AC 1,401 ms
11,648 KB
testcase_18 AC 1,395 ms
11,648 KB
testcase_19 AC 1,392 ms
11,648 KB
testcase_20 AC 1,397 ms
11,904 KB
testcase_21 AC 1,395 ms
11,776 KB
testcase_22 AC 1,396 ms
11,648 KB
testcase_23 AC 1,395 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
#define MOD 1000000007
#define ll long long

int n;
vector<string> vec;
ll d[20][20];
ll dp[1<<20];
ll fact(int n){
    if(n==0)return 1;
    return (fact(n-1)*n)%MOD;
}

signed main(){
    cin>>n;
    vector<ll> ans(n+1,0);
    for(int i=0;i<n;i++){
        string t;
        cin>>t;
        vec.pb(t);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j){
                d[i][j]=1;
                continue;
            }
            for(int k=0;k<min(vec[i].length(),vec[j].length());k++){
                if(vec[i][k]!=vec[j][k]){
                    d[i][j]=k+1;
                    break;
                }
            }
            if(d[i][j]==0){
                d[i][j]=min(vec[i].length(),vec[j].length())+1;
            }
        }
    }
    for(int i=0;i<(1<<n);i++){
        int cnt=0;
        for(int j=0;j<n;j++){
            if(i&(1<<j))cnt++;
        }
        ans[cnt]+=dp[i];
        ans[cnt]%=MOD;
        for(int j=0;j<n;j++){
            if(!(i&(1<<j))){
                ll c=1;
                for(int k=0;k<n;k++){
                    if(!(i&(1<<k))&&j!=k)c=max(c,d[j][k]);
                }
                (dp[i|(1<<j)]+=dp[i]+fact(cnt)*c)%=MOD;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
0