結果
問題 | No.562 超高速一人かるた small |
ユーザー |
![]() |
提出日時 | 2017-08-25 23:52:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 795 ms / 3,000 ms |
コード長 | 3,250 bytes |
コンパイル時間 | 1,158 ms |
コンパイル使用メモリ | 108,988 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-10-15 16:48:17 |
合計ジャッジ時間 | 11,656 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
#pragma region include#include <iostream>#include <iomanip>#include <stdio.h>#include <sstream>#include <algorithm>#include <iterator>#include <cmath>#include <complex>#include <string>#include <cstring>#include <vector>#include <tuple>#include <bitset>#include <queue>#include <complex>#include <set>#include <map>#include <stack>#include <list>#include <fstream>#include <random>//#include <time.h>#include <ctime>#pragma endregion //#include/////////#define REP(i, x, n) for(int i = x; i < n; ++i)#define rep(i,n) REP(i,0,n)#define ALL(X) X.begin(), X.end()/////////#pragma region typedeftypedef long long LL;typedef long double LD;typedef unsigned long long ULL;typedef std::pair<LL,LL> PLL;//typedef std::pair<int,int> PII;//#pragma endregion //typedef////定数const int INF = (int)1e9;const LL MOD = (LL)1e9+7;const LL LINF = (LL)1e18+20;const double PI = acos(-1.0);const double EPS = 1e-9;/////////using namespace::std;/////////#pragma regionlong long bitcount64(long long bits){bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);bits = (bits & 0x0000ffff0000ffff) + (bits >>16 & 0x0000ffff0000ffff);return (bits & 0x00000000ffffffff) + (bits >>32 & 0x00000000ffffffff);}#pragma endregion //その他template<typename T>inline void MAX(T& L,const T R){if( L < R ) L = R;}void solve(){int N;cin >> N;vector<string> str(N);for(int i=0;i<N;++i){cin >> str[i];str[i] += '0';//番兵}vector< vector<int> > cost(N,vector<int>(N,0));for(int i=0;i<N;++i){for(int j=i+1;j<N;++j){//str[i]とstr[j]の共通文字int res = 0;int size = max(str[i].size(),str[j].size());for(res=0;res<size;++res){if( str[i][res] != str[j][res] ){//異なる文字が見つかった。break;}}cost[i][j] = res;cost[j][i] = res;}}vector<LL> fact(N+1,1);for(LL i=2;i<=N;++i){fact[(int)i] = (fact[(int)(i-1)]*i) % MOD;}vector<LL> dp(1<<N,0);for(int s=0;s<(1<<N);++s){for(int i=0;i<N;++i){if( s&(1<<i) ){//読まれている。何もしない}else{//まだ読まれていない。//既に読まれている数。LL count = bitcount64( (LL)s );LL costRes = 0;//疲労度を計算する。for(int j=0;j<N;++j){if( s&(1<<j) ){//既に読まれている。}else if(i!=j){MAX(costRes,(LL)cost[i][j]);}}costRes++;dp[s|(1<<i)] += (dp[s] + costRes*fact[(int)count] );dp[s|(1<<i)] %= MOD;}}}vector<LL> ans(N+1,0);for(int s=0;s<(1<<N);++s){int count = 0;count = (int)bitcount64( (LL)s );ans[count] += dp[s];ans[count] %= MOD;}for(int i=1;i<=N;++i){cout << ans[i] << endl;}}#pragma region mainsigned main(void){std::cin.tie(0);std::ios::sync_with_stdio(false);std::cout << std::fixed;//小数を10進数表示cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別solve();}#pragma endregion //main()