結果
| 問題 |
No.563 超高速一人かるた large
|
| コンテスト | |
| ユーザー |
Pulmn
|
| 提出日時 | 2017-08-18 19:33:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,405 bytes |
| コンパイル時間 | 1,065 ms |
| コンパイル使用メモリ | 106,920 KB |
| 実行使用メモリ | 98,512 KB |
| 最終ジャッジ日時 | 2024-10-14 14:58:25 |
| 合計ジャッジ時間 | 12,768 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 14 |
コンパイルメッセージ
main.cpp: In member function ‘void Trie::dfs(int, vl&, ll&)’:
main.cpp:124:54: warning: ‘S’ may be used uninitialized in this function [-Wmaybe-uninitialized]
124 | for(int j=0;j<=S;j++) for(int k=0;k<=u[v_];k++){
| ~^~~
ソースコード
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll Pow_mod(ll n,ll p){
ll r=1;
for(;p>0;p>>=1){
if(p&1) r=(r*n)%mod;
n=(n*n)%mod;
}
return r;
}
vl fact(3000);
ll Fact(ll n){
if(fact[n]) return fact[n];
if(!n) return fact[n]=1;
return fact[n]=Fact(n-1)*n%mod;
}
ll Div(ll n,ll m){
return n*Pow_mod(m,mod-2)%mod;
}
ll nCk(ll n,ll k){
return Div(Fact(n),Fact(n-k)*Fact(k)%mod);
}
ll nPk(ll n,ll k){
return Div(Fact(n),Fact(n-k));
}
int n;
class Trie{
private:
const int MAX=200005;
int ID=1;
vvl date;
vl a,u,dp;
void Fix(vl& dp,ll h,int v){
if(u[v]==1){
dp[1]=1;
return;
}
for(int i=1;i<=u[v];i++) (dp[i]+=nPk(u[v],i)%mod*h)%=mod;
}
void dfs(int v,vl& dp,ll& h){
if(a[v]==1){
for(int i=0;i<27;i++) if(date[v][i]!=-1) dfs(date[v][i],dp,h);
h++;
return;
}
int S;
bool b=1;
for(int i=0;i<27;i++){
int v_=date[v][i];
if(v_!=-1){
vl DP(u[v_]+1),dp_(u[v]+1);
ll H=0;
dfs(v_,DP,H);
/* if(v==0){
cout<<'B'<<H<<endl;
for(int j=0;j<=n;j++) cout<<DP[j]<<' ';
cout<<endl;
}*/
Fix(DP,H,v_);
if(b){
dp=DP;
b=0;
S=u[v_];
}
else{
/* if(v==0) cout<<S<<' '<<u[v_]<<endl;
if(v==0){
cout<<'B';
for(int j=0;j<=n;j++) cout<<DP[j]<<' ';
cout<<endl;
}*/
for(int j=0;j<=S;j++) for(int k=0;k<=u[v_];k++){
// if(v==0&&j==1&&k==1) cout<<'C'<<dp[j]<<' '<<DP[k]<<' '<<nPk(u[v_],k)<<' '<<nCk(j+k,j)<<endl;
(dp_[j+k]+=(nPk(u[v_],k)*dp[j]%mod+nPk(S,j)*DP[k]%mod)*nCk(j+k,j))%=mod;
}
S+=u[v_];
dp=dp_;
}
/* if(v==0){
cout<<'A';
for(int i=0;i<=n;i++){
cout<<dp[i]<<' ';
}
cout<<endl;
}*/
}
}
for(int i=1;i<=u[v];i++) (dp[i]+=(i-(i==u[v]?1:0))*nPk(u[v],i))%=mod;
/* cout<<'V'<<v<<endl;
for(int i=0;i<=n;i++) cout<<dp[i]<<' ';
cout<<endl;*/
}
public:
Trie(){
date=vvl(MAX,vl(27,-1));
a=u=vl(MAX);
}
void Update(string s){
int S=s.size(),I=0;
u[0]++;
for(int i=0;i<S;i++){
int c=s[i]-'a';
if(date[I][c]==-1){
date[I][c]=ID++;
a[I]++;
}
I=date[I][c];
u[I]++;
}
}
void Solve(){
vl dp(n+1);
ll h=0;
dfs(0,dp,h);
Fix(dp,h,0);
for(int i=1;i<=n;i++){
cout<<(dp[i]-(i-(i==n?1:0))*nPk(n,i)%mod+mod)%mod<<endl;
}
}
};
int main(){
cin>>n;
Trie trie;
for(int i=0;i<n;i++){
string s;
cin>>s;
s+="{";
trie.Update(s);
}
trie.Solve();
}
Pulmn