結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー mugen_1337mugen_1337
提出日時 2021-07-08 15:16:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,517 ms / 3,000 ms
コード長 837 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 205,668 KB
実行使用メモリ 131,852 KB
最終ジャッジ日時 2023-10-14 02:10:04
合計ジャッジ時間 40,915 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
131,728 KB
testcase_01 AC 100 ms
131,556 KB
testcase_02 AC 100 ms
131,852 KB
testcase_03 AC 106 ms
131,548 KB
testcase_04 AC 100 ms
131,824 KB
testcase_05 AC 101 ms
131,660 KB
testcase_06 AC 98 ms
131,560 KB
testcase_07 AC 102 ms
131,624 KB
testcase_08 AC 101 ms
131,632 KB
testcase_09 AC 109 ms
131,544 KB
testcase_10 AC 101 ms
131,612 KB
testcase_11 AC 104 ms
131,604 KB
testcase_12 AC 102 ms
131,552 KB
testcase_13 AC 101 ms
131,552 KB
testcase_14 AC 2,394 ms
131,560 KB
testcase_15 AC 2,509 ms
131,616 KB
testcase_16 AC 2,517 ms
131,564 KB
testcase_17 AC 2,490 ms
131,664 KB
testcase_18 AC 2,507 ms
131,632 KB
testcase_19 AC 2,500 ms
131,608 KB
testcase_20 AC 2,429 ms
131,552 KB
testcase_21 AC 2,011 ms
131,660 KB
testcase_22 AC 2,485 ms
131,556 KB
testcase_23 AC 2,249 ms
131,604 KB
testcase_24 AC 2,428 ms
131,612 KB
testcase_25 AC 2,246 ms
131,604 KB
testcase_26 AC 105 ms
131,556 KB
testcase_27 AC 1,843 ms
131,740 KB
testcase_28 AC 843 ms
131,556 KB
testcase_29 AC 818 ms
131,568 KB
testcase_30 AC 1,195 ms
131,616 KB
testcase_31 AC 1,799 ms
131,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

vector<vector<long long>> dp(1<<14, vector<long long>(1001, 0));

signed main(){
	int N,K;
	cin >> N >> K;
	vector<int> cnt(10, 0), A;
	for(int i = 1; i < 10; i++){
	    cin >> cnt[i];
	    for(int j = 0; j < cnt[i]; j++) A.push_back(i);
	}
	
	auto calc_nxt = [&](int bit, int use){
		auto C = 0, fs = -1;
		for(int i = 0; i < N; i++){
			if(A[i] == use and ((bit >> i) & 1)) C++;
			if(A[i] == use and fs < 0) fs = i;
		}
		if(C >= cnt[use] or fs < 0) return -1;
		return (bit | (1 << (fs + C)));
	};
	
	dp[0][0] = 1;
	
	for(int cur = 0; cur < (1 << N); cur++){
		for(int i = 0; i < K; i++){
			for(int j = 1; j < 10; j++){
				int nxt = calc_nxt(cur, j);
				if(nxt >= 0){
					dp[nxt][(i * 10 + j) % K] += dp[cur][i];
				}
			}
		}
	}
	cout << dp[(1 << N) - 1][0] << endl;
	return 0;
}
0