結果

問題 No.562 超高速一人かるた small
ユーザー IL_mstaIL_msta
提出日時 2017-08-25 23:52:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 734 ms / 3,000 ms
コード長 3,250 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 107,544 KB
実行使用メモリ 11,372 KB
最終ジャッジ日時 2024-04-23 16:20:07
合計ジャッジ時間 10,057 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 74 ms
5,376 KB
testcase_09 AC 712 ms
11,372 KB
testcase_10 AC 159 ms
5,376 KB
testcase_11 AC 337 ms
7,268 KB
testcase_12 AC 71 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 723 ms
11,264 KB
testcase_15 AC 716 ms
11,316 KB
testcase_16 AC 707 ms
11,264 KB
testcase_17 AC 721 ms
11,264 KB
testcase_18 AC 718 ms
11,264 KB
testcase_19 AC 734 ms
11,264 KB
testcase_20 AC 717 ms
11,264 KB
testcase_21 AC 724 ms
11,332 KB
testcase_22 AC 722 ms
11,288 KB
testcase_23 AC 716 ms
11,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 typedef
typedef 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 region 
long 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 main
signed 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()
0