結果

問題 No.1463 Hungry Kanten
ユーザー se1ka2se1ka2
提出日時 2021-04-02 21:55:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 84,112 KB
実行使用メモリ 19,792 KB
最終ジャッジ日時 2023-08-25 14:57:32
合計ジャッジ時間 2,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

const ll MOD0 = 109348985793;
const ll MOD1 = 1092348904598;

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<P> st;
    for(int b = 0; b < (1 << n); b++){
        int e = 0;
        ll s0 = 1;
        ll s1 = 1;
        ll 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++){
                    s0 = s0 * p.first % MOD0;
                    s1 = s1 * p.first % MOD1;
                }
            }
            t += a[i];
        }
        if(e >= k){
            st.insert(P(s0, s1));
            st.insert(P(t, t));
        }
    }
    cout << (int)st.size() << endl;
}
0