結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー karinohitokarinohito
提出日時 2021-07-31 02:07:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,176 ms / 3,000 ms
コード長 2,275 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 194,060 KB
実行使用メモリ 4,768 KB
最終ジャッジ日時 2023-10-14 10:11:01
合計ジャッジ時間 26,455 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
testcase_04 AC 6 ms
4,352 KB
testcase_05 AC 817 ms
4,352 KB
testcase_06 AC 816 ms
4,352 KB
testcase_07 AC 819 ms
4,352 KB
testcase_08 AC 762 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1,173 ms
4,508 KB
testcase_12 AC 1,092 ms
4,388 KB
testcase_13 AC 1,171 ms
4,632 KB
testcase_14 AC 1,176 ms
4,500 KB
testcase_15 AC 1,170 ms
4,480 KB
testcase_16 AC 1,171 ms
4,616 KB
testcase_17 AC 371 ms
4,348 KB
testcase_18 AC 425 ms
4,348 KB
testcase_19 AC 634 ms
4,348 KB
testcase_20 AC 230 ms
4,352 KB
testcase_21 AC 41 ms
4,352 KB
testcase_22 AC 908 ms
4,348 KB
testcase_23 AC 962 ms
4,484 KB
testcase_24 AC 1,091 ms
4,436 KB
testcase_25 AC 1,120 ms
4,488 KB
testcase_26 AC 1,155 ms
4,412 KB
testcase_27 AC 1,162 ms
4,436 KB
testcase_28 AC 1,169 ms
4,608 KB
testcase_29 AC 1,166 ms
4,768 KB
testcase_30 AC 1,168 ms
4,520 KB
testcase_31 AC 1,166 ms
4,616 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<vll> BOX;
//max C size 通りの全列挙
void next_combination(ll size, ll max, vll now_vector) {
	ll now_size = now_vector.size();
	if (now_size == size) {
		BOX.push_back(now_vector);
	}
	else {
		vll 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() {
	ll N, K;
	cin >> N >> K;
	vector<vll> permA;
	vll d;
	rep(i, N / 2) {
		d.push_back(i);
	}
	do {
		permA.push_back(d);
	} while (next_permutation(all(d)));

	vll C(9);
	vll D;
	vll per(15, 1);
	rep(i, 14) {
		per[i + 1] = per[i] * (i + 1);
	}
	ll PPP = 1;
	rep(i, 9) {
		cin >> C[i];
		PPP *= per[C[i]];
		rep(j, C[i])D.push_back(i + 1);
	}
	ll pp = 1;
	rep(i, N / 2) {
		pp *= 10;

	}
	next_combination(N / 2, N, {});
	ll an = 0;
	set<vll> Poo;
	rep(i, BOX.size()) {
		unordered_map<ll, ll> M1;
		vll AUU = BOX[i];
		vll AU;
		set<ll> S; vll CC(9, 0);
		rep(k, AUU.size()) {
			S.insert(AUU[k]);
			AU.push_back(D[AUU[k]]);
			CC[AU[k]-1]++;

		}
		ll dd = 1;
		rep(i, 9) {
			dd *= per[CC[i]];
		}
		if (Poo.count(AU))continue;
		Poo.insert(AU);
		vll BU;
		rep(k, N) {
			if (!S.count(k))BU.push_back(D[k]);
		}
		ll kk = 1;

		rep(nu, permA.size()) {
			kk = 1;
			ll x = 0;
			rep(u, N / 2) {
				x += AU[permA[nu][u]] * kk;
				kk *= 10;
				kk %= K;
				x %= K;
			}
			M1[x]++;
		}
		/*do {
			kk = 1;
			ll x = 0;
			rep(u, AU.size()) {
				x += AU[u] * kk;
				kk *= 10;
				kk %= K;
				x %= K;
			}
			M1[x]++;

		} while (next_permutation(all(AU)));*/

		ll pp = kk;
		do {
			kk = pp;
			ll x = 0;
			rep(u, BU.size()) {
				x += BU[u] * kk;
				kk *= 10;
				kk %= K;
				x %= K;
			}
			if (x == 0)x += K;
			an += M1[K - x]/dd;

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


	}
	cout << an << endl;
}
0