結果
問題 |
No.1634 Sorting Integers (Multiple of K) Hard
|
ユーザー |
|
提出日時 | 2021-07-31 02:38:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 443 ms / 3,000 ms |
コード長 | 1,735 bytes |
コンパイル時間 | 2,369 ms |
コンパイル使用メモリ | 198,264 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-14 06:16:25 |
合計ジャッジ時間 | 10,833 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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<vector<int>> BOX; //max C size 通りの全列挙 int k = 0; vector<int> now_vector; void next_combination(int size, int max, int k) { if (k == size) { BOX.push_back(now_vector); } else { if (k == 0) { for (int i = 0; i < max; i++) { now_vector[k] = i; k++; next_combination(size, max, k); k--; } } else { int LAST = now_vector[k - 1]; for (int i = LAST + 1; i < max; i++) { now_vector[k] = i; k++; next_combination(size, max, k); k--; } } } 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; now_vector.assign(n, -1); next_combination(n, N, 0); 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()) { string AU; set<int> S; rep(k, n) { S.insert(BOX[i][k]); AU.push_back(D[BOX[i][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; unordered_map<ll, ll> M1; 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; }