結果
| 問題 |
No.562 超高速一人かるた small
|
| コンテスト | |
| ユーザー |
gzlcp
|
| 提出日時 | 2017-08-25 23:32:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,566 bytes |
| コンパイル時間 | 989 ms |
| コンパイル使用メモリ | 110,068 KB |
| 実行使用メモリ | 172,288 KB |
| 最終ジャッジ日時 | 2024-10-15 16:44:24 |
| 合計ジャッジ時間 | 6,307 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 -- * 1 |
| other | AC * 7 TLE * 1 -- * 13 |
ソースコード
#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);
ll dp[n][1<<n];
REP(i,n) {
REP(j,1<<n) dp[i][j]=0;
}
ll 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;
}
}
REP(j,1<<n) {
REP(i,n) {
vector<ll> p;
vector<ll> q;
ll buf=j;
bool d=false;
REP(k,n) {
if(buf%2==1) {
p.pb(k);
if(i==k) d=true;
}
else q.pb(k);
buf/=2;
}
if(!d) continue;
ll foo=0;
REP(k,q.size()) {
foo=max(icchi[i][q[k]],foo);
}
++foo;
foo*=fact(p.size()-1);
if(p.size()==1) dp[i][j]=foo%MOD;
else {
REP(k,p.size()) {
if(p[k]==i) continue;
foo+=dp[p[k]][j^(1<<i)];
foo%=MOD;
}
dp[i][j]=foo;
}
res[p.size()-1]+=dp[i][j];
res[p.size()-1]%=MOD;
}
}
REP(i,n) cout<<res[i]<<endl;
}
gzlcp