結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー logxlogx
提出日時 2021-07-30 21:53:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 731 ms / 3,000 ms
コード長 2,646 bytes
コンパイル時間 2,142 ms
コンパイル使用メモリ 200,504 KB
実行使用メモリ 130,984 KB
最終ジャッジ日時 2023-10-14 04:30:26
合計ジャッジ時間 13,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 4 ms
4,372 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 687 ms
124,908 KB
testcase_15 AC 723 ms
130,984 KB
testcase_16 AC 731 ms
130,960 KB
testcase_17 AC 722 ms
130,928 KB
testcase_18 AC 722 ms
130,928 KB
testcase_19 AC 723 ms
130,928 KB
testcase_20 AC 724 ms
130,944 KB
testcase_21 AC 633 ms
115,288 KB
testcase_22 AC 709 ms
128,672 KB
testcase_23 AC 711 ms
128,672 KB
testcase_24 AC 708 ms
128,684 KB
testcase_25 AC 697 ms
127,412 KB
testcase_26 AC 3 ms
4,352 KB
testcase_27 AC 517 ms
95,124 KB
testcase_28 AC 218 ms
41,604 KB
testcase_29 AC 220 ms
42,312 KB
testcase_30 AC 327 ms
60,836 KB
testcase_31 AC 518 ms
94,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using mint=atcoder::modint1000000007;
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}



int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/
    
    int n,k;
    cin >> n >> k;
    int a[n];
    int cnt[10];
    int sz=0;
    rep(i,9){
        int t;
        cin >> t;
        cnt[i+1]=t;
        rep(j,t)a[sz]=i+1, sz++;
    }
    ll dp[1<<n][k]={};
    dp[0][0]=1;
    rep(i,1<<n)rep(j,k)rep(l,n){
        if(!mybit(i,l)){
            dp[i|1<<l][(10*j+a[l])%k]+=dp[i][j];
        }
    }
    ll fac[10]={};
    fac[0]=1;
    rep(i,9)fac[i+1]=fac[i]*(i+1);
    rep(i,9){
        dp[(1<<n)-1][0]/=fac[cnt[i+1]];
    }
    cout << dp[(1<<n)-1][0] << newl;
}
0