結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー publflpublfl
提出日時 2021-07-30 21:24:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,367 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 70,936 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-14 03:18:59
合計ジャッジ時間 6,459 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,696 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 9 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>

int limit,a,b;
std::vector<int> V,V1,V2;
std::map<long long int,int> M,check1,check2;

long long int P[110];
long long int ans = 0;
void func(int k)
{
	if(k>=a)
	{
		if(V1.size()!=limit) return;
		
		M.clear();
		check2.clear();
		std::vector<int> W1 = V1, W2 = V2;
		std::sort(W1.begin(),W1.end());
		std::sort(W2.begin(),W2.end());
		do{
			long long int sum = 0;
			for(int i=0;i<limit;i++) sum += P[i]*W1[i];
			if(check1[sum]>0) continue;
			check1[sum] = 1;
			M[sum%b]++;
		}while(std::next_permutation(W1.begin(),W1.end()));
		
		do{
			long long int sum = 0;
			for(int i=limit;i<a;i++) sum += P[i]*W2[i-limit];
			if(check2[sum]>0) continue;
			
			check2[sum] = 1;
			ans += M[(b-sum%b)%b];
		}while(std::next_permutation(W2.begin(),W2.end()));
		return;
	}
	
	V1.push_back(V[k]);
	func(k+1);
	V1.pop_back();
	
	V2.push_back(V[k]);
	func(k+1);
	V2.pop_back();
	
}

int c[110];

int main()
{
	scanf("%d%d",&a,&b);
	for(int i=1;i<=9;i++) scanf("%d",&c[i]);
	if(a==1)
	{
		for(int i=1;i<=9;i++)
		{
			if(c[i]==1)
			{
				if(i%b==0) printf("1");
				else printf("0");
				return 0;
			}
		}
	}
	
	for(int i=1;i<=9;i++) while(c[i]--) V.push_back(i);
	P[0] = 1;
	for(int i=1;i<a;i++) P[i] = (10*P[i-1]);
	if(a%2==0) limit = a/2;
	else limit = (a+1)/2;
	
	func(0);
	printf("%lld",ans);
}
0