結果

問題 No.562 超高速一人かるた small
ユーザー 小指が強い人小指が強い人
提出日時 2017-08-26 22:40:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 710 ms / 3,000 ms
コード長 3,413 bytes
コンパイル時間 1,752 ms
コンパイル使用メモリ 176,696 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2024-04-23 17:20:16
合計ジャッジ時間 10,964 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 75 ms
6,940 KB
testcase_09 AC 701 ms
11,596 KB
testcase_10 AC 156 ms
6,940 KB
testcase_11 AC 330 ms
7,576 KB
testcase_12 AC 75 ms
6,940 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 705 ms
11,640 KB
testcase_15 AC 692 ms
11,708 KB
testcase_16 AC 710 ms
11,536 KB
testcase_17 AC 698 ms
11,644 KB
testcase_18 AC 698 ms
11,604 KB
testcase_19 AC 705 ms
11,676 KB
testcase_20 AC 696 ms
11,688 KB
testcase_21 AC 700 ms
11,660 KB
testcase_22 AC 707 ms
11,820 KB
testcase_23 AC 704 ms
11,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < (ll)n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T, class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<char c = ' ',class T> void write(T a){cout << fixed << setprecision(15) << a << endl;}
template<char c = ' ',class T,class ...Args> void write(T a, Args... args){cout << fixed << setprecision(4) << a << c; write<c>(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ull gcd(ull a, ull b){while(true){ull k = a % b;if(k == 0)return b;a = b;b = k;}}
ull lcm(ull a, ull b){return a*b/gcd(a,b);}
ull comb(ull n, ull m){ull p=1;m=min(m,n-m);for(ull i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int n;
    vector<string> s;
    vector<int> mat[1000];
    read(n);
    s.resize(n);
    rep(i,n)read(s[i]);
    rep(i,n)mat[i].resize(n,0);
    rep(i,n){
        rep(j,n){
            if(i==j){
                mat[i][j]=1;
                //cout<<mat[i][j]<<" ";
                continue;
            }
            int k=0;
            int mn=min(s[i].size(),s[j].size());
            while(k<mn){
                if(s[i][k]!=s[j][k])break;
                k++;
            }
            mat[i][j]=k+1;
            //cout<<mat[i][j]<<" ";
        }
        //cout<<endl;
    }
    //write("");
    ll frac[50]={1};
    REP(i,1,n)frac[i]=(frac[i-1]*i)%MD;
    int pn=(int)pow(2,n);
    vector<ll> dp(pn);
    vector<ll> res(n+1);
    rep(i,pn){
        int bct=0;
        rep(j,n){
            int bon=1<<j;
            if((i&bon)>0){
                bct++;
                continue;
            }
            int bit=i|bon;
            int mx=0;
            int bct2=0;
            rep(k,n){
                if((i&(1<<k))>0){
                    bct2++;
                    continue;
                }
                mx=max(mx,mat[j][k]);
            }
            //write(i,mx);
            dp[bit]=(dp[bit]+dp[i]+(mx*frac[bct2])%MD)%MD;
        }
        res[bct]=(res[bct]+dp[i])%MD;
    }
    REP(i,1,n+1)write(res[i]);
    return 0;
}
0