結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー karinohitokarinohito
提出日時 2021-07-30 22:47:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,887 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 188,608 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-14 07:09:34
合計ジャッジ時間 6,695 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,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 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
	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;
	rep(i, BOX.size()) {
		map<ll, ll> M1;
		map<ll, ll> M2;
		vll AU = BOX[i];
		set<ll> S;
		rep(k, AU.size()) {
			S.insert(AU[k]);
		}
		vll BU;
		rep(k, N) {
			if (!S.count(k))BU.push_back(k);
		}
		ll kk = 1;
		do {
			kk = 1;
			ll x = 0;
			rep(u, AU.size()) {
				x += D[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 += D[BU[u]] * kk;
				kk *= 10;
				kk %= K;
				x %= K;
			}
			if (x == 0)x += K;
			M2[x]++;

		} while (next_permutation(all(BU)));
		for (auto w : M1) {
			if (M2.count(K - w.first)) {
				an += w.second * M2[K - w.first];
			}
		}
	}
	cout << an/PPP << endl;
}
0