結果

問題 No.562 超高速一人かるた small
ユーザー chocoruskchocorusk
提出日時 2019-09-05 14:24:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 3,000 ms
コード長 1,949 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 101,512 KB
実行使用メモリ 5,772 KB
最終ジャッジ日時 2023-09-02 08:58:38
合計ジャッジ時間 3,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,544 KB
testcase_01 AC 2 ms
5,448 KB
testcase_02 AC 2 ms
5,456 KB
testcase_03 AC 2 ms
5,432 KB
testcase_04 AC 2 ms
5,544 KB
testcase_05 AC 2 ms
5,704 KB
testcase_06 AC 2 ms
5,456 KB
testcase_07 AC 2 ms
5,596 KB
testcase_08 AC 3 ms
5,572 KB
testcase_09 AC 2 ms
5,592 KB
testcase_10 AC 3 ms
5,772 KB
testcase_11 AC 3 ms
5,728 KB
testcase_12 AC 2 ms
5,536 KB
testcase_13 AC 2 ms
5,452 KB
testcase_14 AC 2 ms
5,448 KB
testcase_15 AC 2 ms
5,484 KB
testcase_16 AC 2 ms
5,732 KB
testcase_17 AC 2 ms
5,480 KB
testcase_18 AC 2 ms
5,488 KB
testcase_19 AC 2 ms
5,488 KB
testcase_20 AC 2 ms
5,472 KB
testcase_21 AC 2 ms
5,480 KB
testcase_22 AC 2 ms
5,492 KB
testcase_23 AC 2 ms
5,524 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;
	node(){
		fill(nxt, nxt+27, nullptr);
		cnt=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++;
	}
}
int n, k;
ll c[202020];
void dfs(node* t, int d){
	if(!t) return;
	int x=t->cnt;
	if(d && k>=x) (c[d]+=comb(k, x)*f[x]%MOD*comb(n-x, k-x)%MOD*f[k-x])%=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;
	string s[2020];
	for(int i=0; i<n; i++){
		cin>>s[i];
		m=max(m, (int)s[i].size());
	}
	for(int i=0; i<n; i++){
		while(s[i].size()<m) s[i]+='a'+26;
		add(&t, s[i]);
	}
	fac(n);
	for(int i=1; i<=n; i++){
		fill(c, c+m+1, 0);
		k=i;
		ll ans=0;
		dfs(&t, 0);
		for(ll j=1; j<=m; j++){
			(ans+=j*(c[j]-c[j-1]+MOD))%=MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}
0