結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー karinohitokarinohito
提出日時 2021-07-31 02:25:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 445 ms / 3,000 ms
コード長 1,770 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 195,700 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 10:29:20
合計ジャッジ時間 11,527 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 4 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 92 ms
4,352 KB
testcase_06 AC 92 ms
4,352 KB
testcase_07 AC 94 ms
4,352 KB
testcase_08 AC 271 ms
4,352 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 439 ms
4,352 KB
testcase_12 AC 363 ms
4,352 KB
testcase_13 AC 441 ms
4,348 KB
testcase_14 AC 445 ms
4,356 KB
testcase_15 AC 434 ms
4,356 KB
testcase_16 AC 438 ms
4,348 KB
testcase_17 AC 99 ms
4,356 KB
testcase_18 AC 125 ms
4,352 KB
testcase_19 AC 190 ms
4,352 KB
testcase_20 AC 120 ms
4,352 KB
testcase_21 AC 18 ms
4,368 KB
testcase_22 AC 178 ms
4,352 KB
testcase_23 AC 240 ms
4,348 KB
testcase_24 AC 356 ms
4,368 KB
testcase_25 AC 389 ms
4,356 KB
testcase_26 AC 424 ms
4,348 KB
testcase_27 AC 430 ms
4,352 KB
testcase_28 AC 437 ms
4,348 KB
testcase_29 AC 438 ms
4,348 KB
testcase_30 AC 438 ms
4,352 KB
testcase_31 AC 440 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;

vector<vector<int>> BOX;
//max C size 通りの全列挙
void next_combination(int size,int max, vector<int> now_vector) {
	int now_size = now_vector.size();
	if (now_size == size) {
		BOX.push_back(now_vector);
	}
	else {
		vector<int> next = now_vector;
		if (now_size == 0) {
			for (ll i = 0; i < max; i++) {
				next.push_back(i);
				next_combination(size, max, next);
				next.pop_back();
			}
		}
		else {
			ll LAST = next[now_size - 1];
			for (ll i = LAST + 1; i < max; i++) {
				next.push_back(i);
				next_combination(size, max, next);
				next.pop_back();
			}
		}
	}
	return;
}



int main() {
	int N, K;
	cin >> N >> K;

	vector<int> C(9);
	vector<int> D;
	rep(i, 9) {
		cin >> C[i];
		rep(j, C[i])D.push_back(i + 1);
	}
	int n=N/2;
	next_combination(n, N, {});
	ll an = 0;
	set<string> Poo;
	vll kkk(N,1);
	rep(i,N-1){
		kkk[i+1]=kkk[i]*10;
		kkk[i+1]%=K;
	}
	rep(i, BOX.size()) {
		unordered_map<ll, ll> M1;
		vector<int> AUU = BOX[i];
		string AU;
		set<int> S;
		rep(k, n) {
			S.insert(AUU[k]);
			AU.push_back(D[AUU[k]]);
		}
		if (Poo.count(AU))continue;
		Poo.insert(AU);
		string BU;
		rep(k, N) {
			if (!S.count(k))BU.push_back(D[k]);
		}
		ll x = 0;
		do {
			x=0;
			rep(u, n) {
				x += (AU[u]) * kkk[u];
			}
			x %= K;
			M1[x]++;
		} while (next_permutation(all(AU)));

		do {
			x = 0;
			rep(u, N-n) {
				x += (BU[u]) * kkk[u+N/2];
			}
			x%=K;
			if (x == 0)x += K;
			an += M1[K - x];

		} while (next_permutation(all(BU)));


	}
	cout << an << endl;
}
0