結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー kwm_tkwm_t
提出日時 2021-07-31 00:22:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 442 ms / 3,000 ms
コード長 1,857 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 170,440 KB
実行使用メモリ 131,520 KB
最終ジャッジ日時 2023-10-14 09:24:04
合計ジャッジ時間 9,209 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 4 ms
6,704 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 414 ms
131,380 KB
testcase_15 AC 429 ms
131,376 KB
testcase_16 AC 442 ms
131,436 KB
testcase_17 AC 419 ms
131,328 KB
testcase_18 AC 422 ms
131,404 KB
testcase_19 AC 422 ms
131,384 KB
testcase_20 AC 419 ms
131,408 KB
testcase_21 AC 375 ms
131,476 KB
testcase_22 AC 412 ms
131,368 KB
testcase_23 AC 413 ms
131,408 KB
testcase_24 AC 418 ms
131,520 KB
testcase_25 AC 411 ms
131,440 KB
testcase_26 AC 29 ms
101,984 KB
testcase_27 AC 318 ms
131,376 KB
testcase_28 AC 155 ms
120,048 KB
testcase_29 AC 157 ms
119,944 KB
testcase_30 AC 213 ms
129,052 KB
testcase_31 AC 318 ms
131,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
long long dp[1 << 14][1000];
int popcount(long long n) {
	n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555);
	n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333);
	n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f);
	n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff);
	n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff);
	n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff);
	return n;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m; cin >> n >> m;
	vector<long long>fact(17, 1);
	rep2(i, 1, 17)fact[i] = fact[i - 1] * i;

	vector<int>v, c(10);
	rep2(i, 1, 10) {
		cin >> c[i];
		rep(j, c[i])v.push_back(i);
	}
	dp[0][0] = 1;
	rep(i, 1 << n) {
		rep(j, n) {
			if (i &(1 << j))continue;
			rep(k, m) {
				int ni = i | (1 << j);
				int nk = (k * 10 + v[j]) % m;
				dp[ni][nk] += dp[i][k];
			}
		}
	}
	long long ans = dp[(1 << n) - 1][0];
	rep(i, 10)ans /= fact[c[i]];
	cout << ans << endl;
	return 0;
}
0