結果
| 問題 |
No.1634 Sorting Integers (Multiple of K) Hard
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-31 02:12:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 805 ms / 3,000 ms |
| コード長 | 1,973 bytes |
| コンパイル時間 | 2,450 ms |
| コンパイル使用メモリ | 196,636 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 05:12:34 |
| 合計ジャッジ時間 | 18,297 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
ソースコード
//#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);
}
rep(i, 9) {
cin >> C[i];
rep(j, C[i])D.push_back(i + 1);
}
next_combination(N / 2, N, {});
ll an = 0;
set<string> Poo;
rep(i, BOX.size()) {
unordered_map<ll, ll> M1;
vll AUU = BOX[i];
string AU;
set<ll> S;
rep(k, AUU.size()) {
S.insert(AUU[k]);
AU.push_back('0'+D[AUU[k]]);
}
if (Poo.count(AU))continue;
Poo.insert(AU);
string BU;
rep(k, N) {
if (!S.count(k))BU.push_back('0'+D[k]);
}
ll kk = 1;
do {
kk = 1;
ll x = 0;
rep(u, AU.size()) {
x += (AU[u]-'0') * 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]-'0') * kk;
kk *= 10;
kk %= K;
x %= K;
}
if (x == 0)x += K;
an += M1[K - x];
} while (next_permutation(all(BU)));
}
cout << an << endl;
}