結果
問題 | No.1634 Sorting Integers (Multiple of K) Hard |
ユーザー | chocorusk |
提出日時 | 2021-07-30 21:40:57 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,521 ms / 3,000 ms |
コード長 | 1,918 bytes |
コンパイル時間 | 3,596 ms |
コンパイル使用メモリ | 194,844 KB |
実行使用メモリ | 88,996 KB |
最終ジャッジ日時 | 2023-10-14 03:58:02 |
合計ジャッジ時間 | 33,553 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 1 ms
4,356 KB |
testcase_03 | AC | 61 ms
14,048 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 191 ms
4,348 KB |
testcase_06 | AC | 169 ms
4,356 KB |
testcase_07 | AC | 197 ms
4,352 KB |
testcase_08 | AC | 520 ms
55,284 KB |
testcase_09 | AC | 1 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,372 KB |
testcase_11 | AC | 915 ms
88,848 KB |
testcase_12 | AC | 2,521 ms
79,672 KB |
testcase_13 | AC | 901 ms
88,740 KB |
testcase_14 | AC | 2,310 ms
88,636 KB |
testcase_15 | AC | 2,348 ms
88,588 KB |
testcase_16 | AC | 890 ms
88,784 KB |
testcase_17 | AC | 318 ms
21,612 KB |
testcase_18 | AC | 214 ms
26,896 KB |
testcase_19 | AC | 689 ms
43,124 KB |
testcase_20 | AC | 291 ms
40,116 KB |
testcase_21 | AC | 27 ms
8,160 KB |
testcase_22 | AC | 1,745 ms
27,924 KB |
testcase_23 | AC | 2,164 ms
47,720 KB |
testcase_24 | AC | 2,163 ms
67,244 KB |
testcase_25 | AC | 2,313 ms
73,516 KB |
testcase_26 | AC | 2,015 ms
82,192 KB |
testcase_27 | AC | 1,431 ms
85,296 KB |
testcase_28 | AC | 1,469 ms
88,788 KB |
testcase_29 | AC | 771 ms
88,996 KB |
testcase_30 | AC | 823 ms
88,748 KB |
testcase_31 | AC | 855 ms
88,736 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; int n, k; int c[10]; int n1,n2; map<pair<int, ll>, int> mp; ll ans; void dfs(ll v, ll r, int t){ if(t==n1){ mp[make_pair(r, v)]++; return; } ll r1=(r*10+1)%k; for(int i=1; i<=9; i++){ ll d=((v>>((i-1)<<2))&15); if(c[i]>d){ v+=(1ll<<((i-1)<<2)); dfs(v, r1, t+1); v-=(1ll<<((i-1)<<2)); } r1++; if(r1>=k) r1-=k; } } ll q; ll c0; void dfs2(ll v, ll r, int t){ if(t==n2){ ll x=(k-q*r%k); if(x>=k) x-=k; ll w=c0-v; auto itr=mp.find(make_pair(x, w)); if(itr!=mp.end()){ ans+=itr->second; } return; } ll r1=(r*10+1)%k; for(int i=1; i<=9; i++){ ll d=((v>>((i-1)<<2))&15); if(c[i]>d){ v+=(1ll<<((i-1)<<2)); dfs2(v, r1, t+1); v-=(1ll<<((i-1)<<2)); } r1++; if(r1>=k) r1-=k; } } int main() { cin>>n>>k; for(int i=1; i<=9; i++){ cin>>c[i]; c0^=((ll)c[i]<<((i-1)*4)); } n1=min(7, n); dfs(0, 0, 0); if(n1==n){ for(auto p:mp) if(p.first.first==0) ans+=p.second; cout<<ans<<endl; return 0; } n2=n-n1; q=1; for(int i=0; i<n1; i++) q=q*10%k; dfs2(0, 0, 0); cout<<ans<<endl; return 0; }