結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー kotatsugamekotatsugame
提出日時 2021-07-30 22:22:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 765 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 79,652 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-14 05:33:06
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 4 ms
4,352 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:38:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   38 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<map>
using namespace std;
int N,K,c[14];
long V=1;
map<pair<int,int>,long>mp;
void dfs1(int k,int now,int rest)
{
	if(rest==0)
	{
		mp[make_pair(k,now)]++;
	}
	else
	{
		for(int i=0;i<N;i++)if(!(k>>i&1))
		{
			dfs1(k|1<<i,(now*10L+c[i])%K,rest-1);
		}
	}
}
long ans=0;
long P10;
void dfs2(int k,int now,int rest)
{
	if(rest==0)
	{
		pair<int,int>p=make_pair((1<<N)-1-k,(K-now*P10%K)%K);
		if(mp.find(p)!=mp.end())ans+=mp[p];
	}
	else
	{
		for(int i=0;i<N;i++)if(!(k>>i&1))
		{
			dfs2(k|1<<i,(now*10L+c[i])%K,rest-1);
		}
	}
}
main()
{
	cin>>N>>K;
	int sz=0;
	for(int i=1;i<=9;i++)
	{
		int C;cin>>C;
		for(;C;V*=C--)c[sz++]=i;
	}
	dfs1(0,0,N/2);
	P10=1;
	for(int i=0;i<N/2;i++)P10*=10;
	P10%=K;
	dfs2(0,0,N-N/2);
	cout<<ans/V<<endl;
}
0