結果

問題 No.1463 Hungry Kanten
ユーザー se1ka2se1ka2
提出日時 2021-04-02 21:51:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,393 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-08-25 14:56:25
合計ジャッジ時間 2,803 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef pair<int, int> P;

std::vector<int> enum_prime(int n){     // containing n
    std::vector<int> res;
    if (n <= 1) return res;
    std::vector<bool> p(n + 1);
    fill(p.begin() + 2, p.end(), true);
    for(int i = 2; i <= n; i++){
        if(p[i]){
            res.push_back(i);
            for(int j = i * 2; j <= n; j += i) p[j] = false;
        }
    }
    return res;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> prime = enum_prime(1000);
    int a[20];
    vector<P> v[20];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        int b = a[i];
        for(int p : prime){
            if(b % p == 0){
                int c = 0;
                while(b % p == 0){
                    c++;
                    b /= p;
                }
                v[i].push_back(P(p, c));
            }
        }
    }
    set<int> st;
    for(int b = 0; b < (1 << n); b++){
        int e = 0;
        int s = 1;
        int t = 0;
        for(int i = 0; i < n; i++){
            if(!((b >> i) & 1)) continue;
            e++;
            for(P p : v[i]){
                for(int j = 0; j < p.second; j++) s *= p.first;
            }
            t += a[i];
        }
        if(e >= k){
            st.insert(s);
            st.insert(t);
        }
    }
    cout << (int)st.size() << endl;
}
0