結果

問題 No.1463 Hungry Kanten
ユーザー ぷらぷら
提出日時 2021-05-08 16:48:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,532 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 217,620 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-10-15 04:19:22
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 2 ms
4,352 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

struct PrimeFact {
    vector<int> spf;
    PrimeFact(int N) {
        init(N);
    }
    void init(int N) {
        spf.assign(N+1,0);
        for(int i = 0; i <= N; i++) {
            spf[i] = i;
        }
        for(int i = 2; i * i <= N; i++) {
            if(spf[i] == i) {
                for(int j = i*i; j <= N; j += i) {
                    if(spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    map<int,int> get(int n) {
        map<int,int> m;
        while(n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};

int main() {
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    PrimeFact prime(1005);
    map<map<int,int>,bool>flag;
    for(int i = 0; i < (1 << N); i++) {
        if(__builtin_popcount(i) < K) {
            continue;
        }
        int X = 0;
        for(int j = 0; j < N; j++) {
            if(1 & (i >> j)) {
                X += A[j];
            }
        }
        map<int,int> x = prime.get(X);
        flag[x] = true;
        x.clear();
        for(int j = 0; j < N; j++) {
            if(1 & (i >> j)) {
                int B = A[j];
                map<int,int> y = prime.get(B);
                for(auto Y:y) {
                    x[Y.first] += Y.second;
                }
            }
        }
        flag[x] = true;
    }
    cout << flag.size() << endl;
}
0