結果

問題 No.562 超高速一人かるた small
ユーザー gzlcpgzlcp
提出日時 2017-08-26 00:01:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,821 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 118,936 KB
実行使用メモリ 253,320 KB
最終ジャッジ日時 2024-04-23 16:20:54
合計ジャッジ時間 19,257 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 10 ms
6,940 KB
testcase_08 AC 156 ms
29,980 KB
testcase_09 WA -
testcase_10 AC 338 ms
59,684 KB
testcase_11 WA -
testcase_12 AC 160 ms
29,980 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<random>
#include<time.h>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

ll fact(ll a) {
	if(a==0) return 1;
	else return (a*fact(a-1))%MOD;
}

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<string> s(n);
	REP(i,n) cin>>s[i];
	vector<ll> res(n,0);
	vector<vector<ll> > dp(n,vector<ll>(1<<n,0));
	int icchi[n][n];
	REP(i,n) {
		REP(j,n) {
			if(i==j) continue;
			ll pos=0;
			while(pos<s[i].size()&&pos<s[j].size()&&s[i][pos]==s[j][pos]) ++pos;
			icchi[i][j]=pos;
		}
	}
	vector<vector<int> > kyori(n,vector<int>(1<<n,0));
	for(int i=(1<<n)-1; i>=0; --i) {
		vector<ll> p;
		vector<ll> q;
		ll buf=i;
		REP(k,n) {
			if(buf%2==1) {
				p.pb(k);
			}
			else q.pb(k);
			buf/=2;
		}
		for(int j=0; j<p.size(); ++j) {
			if(i==(1<<n)-1) {
				kyori[p[j]][i]=0;
			} else {
				kyori[p[j]][i]=max(kyori[p[j]][i^(1<<q[0])],icchi[p[j]][q[0]]);
			}
		}
	}
	REP(j,1<<n) {
		vector<ll> p;
		vector<ll> q;
		ll buf=j;
		REP(k,n) {
			if(buf%2==1) {
				p.pb(k);
			}
			else q.pb(k);
			buf/=2;
		}
		REP(i,p.size()) {
			ll foo=kyori[p[i]][j];
			++foo;
			foo*=fact(p.size()-1);
			if(p.size()==1) dp[i][j]=foo%MOD;
			else {
				dp[i][j]=foo%MOD;
			}
			res[p.size()-1]+=dp[i][j];
			res[p.size()-1]%=MOD;
		}
	}
	REP(i,n) {
		if(i!=0) {
			res[i]=res[i-1]*(n-i)+res[i];
			cout<<res[i]%MOD<<endl;
		}
		else cout<<res[i]<<endl;
	}
}
0