結果

問題 No.1631 Sorting Integers (Multiple of K) Easy
ユーザー ぷらぷら
提出日時 2021-07-30 21:37:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 2,522 ms
コンパイル使用メモリ 211,208 KB
実行使用メモリ 49,916 KB
最終ジャッジ日時 2023-10-14 03:49:22
合計ジャッジ時間 7,390 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 7 ms
4,368 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 WA -
testcase_13 WA -
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];
        for(int j = 0; j < tmp[i]; j++) {
            if(a.size()+1 <= N/2) {
                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