結果

問題 No.563 超高速一人かるた large
ユーザー chocoruskchocorusk
提出日時 2019-09-05 15:53:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 3,000 ms
コード長 1,906 bytes
コンパイル時間 864 ms
コンパイル使用メモリ 99,668 KB
実行使用メモリ 58,832 KB
最終ジャッジ日時 2023-09-02 11:06:34
合計ジャッジ時間 2,593 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,484 KB
testcase_01 AC 2 ms
5,488 KB
testcase_02 AC 2 ms
5,436 KB
testcase_03 AC 4 ms
6,708 KB
testcase_04 AC 6 ms
7,936 KB
testcase_05 AC 7 ms
8,500 KB
testcase_06 AC 22 ms
15,124 KB
testcase_07 AC 28 ms
17,600 KB
testcase_08 AC 47 ms
23,524 KB
testcase_09 AC 72 ms
28,928 KB
testcase_10 AC 39 ms
6,976 KB
testcase_11 AC 43 ms
6,632 KB
testcase_12 AC 43 ms
6,432 KB
testcase_13 AC 43 ms
6,392 KB
testcase_14 AC 43 ms
6,676 KB
testcase_15 AC 42 ms
6,404 KB
testcase_16 AC 44 ms
6,864 KB
testcase_17 AC 11 ms
5,816 KB
testcase_18 AC 49 ms
8,280 KB
testcase_19 AC 60 ms
58,832 KB
testcase_20 AC 35 ms
12,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[200020], invf[200020];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
struct node{
	node* nxt[27];
	int cnt;
	bool exist;
	node(){
		fill(nxt, nxt+27, nullptr);
		cnt=0;
		exist=0;
	}
};
void add(node* t, string p){
	node* t0=t;
	for(int i=0; i<p.size(); i++){
		if(!t0->nxt[p[i]-'a']){
			t0->nxt[p[i]-'a']=new node();
		}
		t0=t0->nxt[p[i]-'a'];
		t0->cnt++;
	}
	t0->exist=1;
}
int n;
ll a[202020];
void dfs(node* t, int d){
	if(!t) return;
	int x=t->cnt;
	if(t->exist) (a[x]+=d)%=MOD;
	else (a[x]+=MOD-1)%=MOD;
	for(int i=0; i<=26; i++){
		if(!t->nxt[i]) continue;
		dfs(t->nxt[i], d+1);
	}
}
int main()
{
	cin>>n;
	node t;
	int m=0;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		s+='a'+26;
		m=max(m, (int)s.size());
		add(&t, s);
	}
	fac(n);
	dfs(&t, 0);
	for(int i=1; i<=n; i++){
		ll ans=0;
		for(int j=1; j<=i; j++){
			(ans+=comb(i, j)*f[j]%MOD*comb(n-j, i-j)%MOD*f[i-j]%MOD*a[j])%=MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}
0