結果
問題 | No.1634 Sorting Integers (Multiple of K) Hard |
ユーザー | kotatsugame |
提出日時 | 2021-07-30 22:34:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,803 ms / 3,000 ms |
コード長 | 1,692 bytes |
コンパイル時間 | 783 ms |
コンパイル使用メモリ | 78,376 KB |
実行使用メモリ | 105,088 KB |
最終ジャッジ日時 | 2023-10-14 05:59:29 |
合計ジャッジ時間 | 58,396 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,352 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 4 ms
4,352 KB |
testcase_04 | AC | 1,317 ms
104,852 KB |
testcase_05 | AC | 1,314 ms
104,852 KB |
testcase_06 | AC | 1,430 ms
104,852 KB |
testcase_07 | AC | 1,317 ms
105,088 KB |
testcase_08 | AC | 2,231 ms
104,932 KB |
testcase_09 | AC | 2 ms
4,352 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2,354 ms
104,856 KB |
testcase_12 | AC | 2,803 ms
104,800 KB |
testcase_13 | AC | 2,343 ms
104,860 KB |
testcase_14 | AC | 2,604 ms
104,804 KB |
testcase_15 | AC | 2,615 ms
104,732 KB |
testcase_16 | AC | 2,341 ms
104,936 KB |
testcase_17 | AC | 2,559 ms
104,840 KB |
testcase_18 | AC | 2,307 ms
104,724 KB |
testcase_19 | AC | 2,626 ms
104,848 KB |
testcase_20 | AC | 1,028 ms
61,416 KB |
testcase_21 | AC | 1,006 ms
61,484 KB |
testcase_22 | AC | 2,528 ms
104,748 KB |
testcase_23 | AC | 2,727 ms
104,720 KB |
testcase_24 | AC | 2,780 ms
104,920 KB |
testcase_25 | AC | 2,663 ms
104,800 KB |
testcase_26 | AC | 2,579 ms
104,724 KB |
testcase_27 | AC | 2,362 ms
104,780 KB |
testcase_28 | AC | 2,286 ms
104,836 KB |
testcase_29 | AC | 2,078 ms
104,864 KB |
testcase_30 | AC | 1,774 ms
104,844 KB |
testcase_31 | AC | 2,218 ms
104,744 KB |
コンパイルメッセージ
main.cpp:22:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type] 22 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; int N,K,c[14]; long V=1; vector<int>A[1<<14]; void dfs(int k,int now,int rest) { if(rest==0) { A[k].push_back(now); } else { for(int i=0;i<N;i++)if(!(k>>i&1)) { dfs(k|1<<i,(now*10L+c[i])%K,rest-1); } } } main() { cin>>N>>K; int sz=0; for(int i=1;i<=9;i++) { int C;cin>>C; for(;C;V*=C--)c[sz++]=i; } long ans=0; dfs(0,0,N/2); if(N%2==0) { long P10=1; for(int i=0;i<N/2;i++)P10=P10*10%K; int comb=(1<<N/2)-1; while(comb<1<<N) { vector<int>Ac=A[comb]; for(int&a:Ac)a=(K-P10*a%K)%K; sort(Ac.begin(),Ac.end()); int u=(1<<N)-1-comb; sort(A[u].begin(),A[u].end()); int ic=0,iu=0; while(ic<Ac.size()&&iu<A[u].size()) { if(Ac[ic]<A[u][iu])ic++; else if(Ac[ic]>A[u][iu])iu++; else { int l=0; int p=A[u][iu]; while(ic<Ac.size()&&p==Ac[ic])ic++,l++; while(iu<A[u].size()&&p==A[u][iu])iu++,ans+=l; } } int x=comb&-comb,y=comb+x; comb=(comb&~y)/x>>1|y; } } else { dfs(0,0,N-N/2); long P10=1; for(int i=0;i<N/2;i++)P10=P10*10%K; int comb=(1<<N-N/2)-1; while(comb<1<<N) { for(int&a:A[comb])a=(K-P10*a%K)%K; sort(A[comb].begin(),A[comb].end()); int u=(1<<N)-1-comb; sort(A[u].begin(),A[u].end()); int ic=0,iu=0; while(ic<A[comb].size()&&iu<A[u].size()) { if(A[comb][ic]<A[u][iu])ic++; else if(A[comb][ic]>A[u][iu])iu++; else { int l=0; int p=A[u][iu]; while(ic<A[comb].size()&&p==A[comb][ic])ic++,l++; while(iu<A[u].size()&&p==A[u][iu])iu++,ans+=l; } } int x=comb&-comb,y=comb+x; comb=(comb&~y)/x>>1|y; } } cout<<ans/V<<endl; }