結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 21:40:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,661 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 210,784 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 03:54:47
合計ジャッジ時間 7,284 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 22 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 TLE -
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 <bits/stdc++.h>
using namespace std;

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>tmp(9),a,b;
    for(int i = 0; i < 9; i++) {
        cin >> tmp[i];
        bool flag = a.size()+1 < N/2;
        for(int j = 0; j < tmp[i]; j++) {
            if(flag) {
                a.push_back(i+1);
            }
            else {
                b.push_back(i+1);
            }
        }
    }
    vector<map<int,int>>mp(1<<N);
    for(int i = 0; i < (1 << N); i++) {
        if(__builtin_popcount(i) != a.size()) {
            continue;
        }
        do {
            int cnt = 0;
            long long tmp2 = 1;
            long long tmp3 = 0;
            for(int j = 0; j < N; j++) {
                if(1 & (i >> j)) {
                    tmp3 += tmp2*a[cnt]%K;
                    tmp3 %= K;
                    cnt++;
                }
                tmp2 *= 10;
                tmp2 %= K;
            }
            mp[i][tmp3]++;
        }while(next_permutation(a.begin(),a.end()));
    }
    long long ans = 0;
    for(int i = 0; i < (1 << N); i++) {
        if(__builtin_popcount(i) != b.size()) {
            continue;
        }
        do {
            int cnt = 0;
            long long tmp2 = 1;
            long long tmp3 = 0;
            for(int j = 0; j < N; j++) {
                if(1 & (i >> j)) {
                    tmp3 += tmp2*b[cnt]%K;
                    tmp3 %= K;
                    cnt++;
                }
                tmp2 *= 10;
                tmp2 %= K;
            }
            ans += mp[((1 << N)-1)^i][(K-tmp3)%K];
        }while(next_permutation(b.begin(),b.end()));
    }
    cout << ans << endl;
}
0