結果
問題 | No.1634 Sorting Integers (Multiple of K) Hard |
ユーザー | tokusakurai |
提出日時 | 2021-08-12 10:03:11 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 346 ms / 3,000 ms |
コード長 | 2,468 bytes |
コンパイル時間 | 2,176 ms |
コンパイル使用メモリ | 202,816 KB |
実行使用メモリ | 42,504 KB |
最終ジャッジ日時 | 2024-04-25 21:26:11 |
合計ジャッジ時間 | 10,515 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 223 ms
42,372 KB |
testcase_05 | AC | 287 ms
42,436 KB |
testcase_06 | AC | 290 ms
42,492 KB |
testcase_07 | AC | 289 ms
42,324 KB |
testcase_08 | AC | 281 ms
42,392 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 333 ms
42,412 KB |
testcase_12 | AC | 290 ms
42,284 KB |
testcase_13 | AC | 311 ms
42,344 KB |
testcase_14 | AC | 299 ms
42,384 KB |
testcase_15 | AC | 298 ms
42,424 KB |
testcase_16 | AC | 329 ms
42,320 KB |
testcase_17 | AC | 253 ms
42,500 KB |
testcase_18 | AC | 258 ms
42,412 KB |
testcase_19 | AC | 263 ms
42,484 KB |
testcase_20 | AC | 64 ms
42,340 KB |
testcase_21 | AC | 38 ms
42,436 KB |
testcase_22 | AC | 301 ms
42,416 KB |
testcase_23 | AC | 293 ms
42,380 KB |
testcase_24 | AC | 293 ms
42,344 KB |
testcase_25 | AC | 302 ms
42,504 KB |
testcase_26 | AC | 306 ms
42,428 KB |
testcase_27 | AC | 304 ms
42,388 KB |
testcase_28 | AC | 306 ms
42,408 KB |
testcase_29 | AC | 342 ms
42,420 KB |
testcase_30 | AC | 346 ms
42,444 KB |
testcase_31 | AC | 329 ms
42,388 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N, K; cin >> N >> K; vector<int> c(10, 0); rep2(i, 1, 9) cin >> c[i]; vector<ll> pw(8, 1); rep(i, 7) pw[i+1] = pw[i]*10; if(N == 1){ rep(j, 10){ if(c[j] == 1){ cout << (j%K == 0? 1 : 0) << '\n'; return 0; } } } int n = N/2, m = N-n; vector<int> d(10, 0); vector<int> u(n), v(m); ll ans = 0; vector<int> cnt(pw[m], 0); for(int i = pw[n-1]; i < pw[n]; i++){ fill(all(d), 0); int memo = i; bool flag = false; rep(j, n){ int k = memo%10; if(d[k]++ == c[k]) flag = true; u[j] = k; memo /= 10; } rep(j, n-1){ if(u[j] > u[j+1]) flag = true; } if(flag) continue; int ptr = 0; rep(j, 10){ rep(k, c[j]-d[j]){ v[ptr++] = j; } } vector<int> tmp; do{ int r = 0; each(e, v){ r *= 10, r += e; } r %= K; cnt[r]++; tmp.eb(r); } while(next_permutation(all(v))); do{ ll r = 0; each(e, u){ r *= 10, r += e; } r *= pw[m], r %= K; int R = (K-r)%K; if(R < pw[m]) ans += cnt[R]; } while(next_permutation(all(u))); each(e, tmp) cnt[e]--; } cout << ans << '\n'; }