結果
問題 | No.1631 Sorting Integers (Multiple of K) Easy |
ユーザー | chocorusk |
提出日時 | 2021-07-30 21:41:24 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,277 ms / 3,000 ms |
コード長 | 1,918 bytes |
コンパイル時間 | 3,427 ms |
コンパイル使用メモリ | 195,676 KB |
実行使用メモリ | 38,844 KB |
最終ジャッジ日時 | 2023-10-14 03:58:42 |
合計ジャッジ時間 | 18,289 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,352 KB |
testcase_01 | AC | 1 ms
4,348 KB |
testcase_02 | AC | 1 ms
4,348 KB |
testcase_03 | AC | 25 ms
4,352 KB |
testcase_04 | AC | 1 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 1 ms
4,352 KB |
testcase_07 | AC | 1 ms
4,348 KB |
testcase_08 | AC | 1 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,352 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 1 ms
4,352 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,352 KB |
testcase_14 | AC | 627 ms
20,456 KB |
testcase_15 | AC | 2,189 ms
38,696 KB |
testcase_16 | AC | 2,268 ms
38,840 KB |
testcase_17 | AC | 2,256 ms
38,844 KB |
testcase_18 | AC | 2,212 ms
38,692 KB |
testcase_19 | AC | 2,277 ms
38,644 KB |
testcase_20 | AC | 2 ms
4,356 KB |
testcase_21 | AC | 2 ms
4,352 KB |
testcase_22 | AC | 2 ms
4,352 KB |
testcase_23 | AC | 5 ms
4,352 KB |
testcase_24 | AC | 3 ms
4,348 KB |
testcase_25 | AC | 2 ms
4,348 KB |
testcase_26 | AC | 191 ms
4,348 KB |
testcase_27 | AC | 459 ms
15,900 KB |
testcase_28 | AC | 408 ms
10,288 KB |
testcase_29 | AC | 33 ms
5,180 KB |
testcase_30 | AC | 302 ms
10,316 KB |
testcase_31 | AC | 284 ms
12,328 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; }