結果

問題 No.1634 Sorting Integers (Multiple of K) Hard
ユーザー chocoruskchocorusk
提出日時 2021-07-30 21:22:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,909 bytes
コンパイル時間 3,566 ms
コンパイル使用メモリ 197,068 KB
実行使用メモリ 174,112 KB
最終ジャッジ日時 2023-10-14 03:13:25
合計ジャッジ時間 12,965 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 110 ms
24,684 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 569 ms
4,352 KB
testcase_06 AC 492 ms
4,352 KB
testcase_07 AC 529 ms
4,352 KB
testcase_08 AC 793 ms
107,280 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1,362 ms
174,112 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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, vector<int>>, int> mp, mp2;
ll ans;
void dfs(vector<int> v, ll r, int t){
    if(t==n1){
        mp[make_pair(r, v)]++;
        // if(r==0){
        //     for(int i=0; i<3; i++) cout<<v[i];
        //     cout<<endl;
        // }
        return;
    }
    for(int i=1; i<=9; i++){
        if(c[i]>v[i-1]){
            v[i-1]++;
            dfs(v, (r*10+i)%k, t+1);
            v[i-1]--;
        }
    }
}
ll q;
void dfs2(vector<int> v, ll r, int t){
    if(t==n2){
        ll x=(k-q*r%k);
        if(x>=k) x-=k;
        vector<int> w(9);
        for(int i=0; i<9; i++) w[i]=c[i+1]-v[i];
        auto itr=mp.find(make_pair(x, w));
        if(itr!=mp.end()){
            ans+=itr->second;
        }
        return;
    }
    for(int i=1; i<=9; i++){
        if(c[i]>v[i-1]){
            v[i-1]++;
            dfs2(v, (r*10+i)%k, t+1);
            v[i-1]--;
        }
    }
}
int main()
{
	cin>>n>>k;
	for(int i=1; i<=9; i++){
		cin>>c[i];
	}
    n1=min(7, n);
    vector<int> v0(9);
    dfs(v0, 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;
    vector<int> v1(9);
    dfs2(v1, 0, 0);
    cout<<ans<<endl;
    return 0;
}
0