結果

問題 No.917 Make One With GCD
ユーザー tsutajtsutaj
提出日時 2019-10-25 22:40:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 108,176 KB
実行使用メモリ 105,972 KB
最終ジャッジ日時 2023-09-06 16:39:52
合計ジャッジ時間 2,888 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
105,776 KB
testcase_01 AC 2 ms
5,404 KB
testcase_02 AC 2 ms
5,496 KB
testcase_03 AC 10 ms
44,296 KB
testcase_04 AC 9 ms
38,208 KB
testcase_05 AC 17 ms
81,212 KB
testcase_06 AC 25 ms
105,932 KB
testcase_07 AC 23 ms
105,972 KB
testcase_08 AC 6 ms
23,860 KB
testcase_09 AC 23 ms
103,680 KB
testcase_10 AC 23 ms
105,712 KB
testcase_11 AC 23 ms
103,808 KB
testcase_12 AC 24 ms
105,788 KB
testcase_13 AC 19 ms
89,380 KB
testcase_14 AC 22 ms
95,524 KB
testcase_15 AC 21 ms
93,424 KB
testcase_16 AC 20 ms
89,384 KB
testcase_17 AC 5 ms
21,996 KB
testcase_18 AC 17 ms
79,100 KB
testcase_19 AC 3 ms
11,552 KB
testcase_20 AC 7 ms
31,996 KB
testcase_21 AC 13 ms
60,664 KB
testcase_22 AC 10 ms
44,316 KB
testcase_23 AC 20 ms
95,628 KB
testcase_24 AC 14 ms
64,760 KB
testcase_25 AC 21 ms
95,524 KB
testcase_26 AC 5 ms
17,676 KB
testcase_27 AC 3 ms
9,712 KB
testcase_28 AC 3 ms
11,504 KB
testcase_29 AC 3 ms
11,544 KB
testcase_30 AC 6 ms
23,864 KB
testcase_31 AC 2 ms
7,432 KB
testcase_32 AC 3 ms
11,516 KB
testcase_33 AC 3 ms
9,500 KB
testcase_34 AC 2 ms
7,456 KB
testcase_35 AC 3 ms
13,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[51][51 * 10010];

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a%b);
}

int main() {
    int N; cin >> N;
    vector<int> A(N), divs;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        for(int d=1; d*d<=A[i]; d++) {
            if(A[i] % d == 0) {
                divs.emplace_back(d);
                if(A[i] / d != d) divs.emplace_back(A[i] / d);
            }
        }
    }

    divs.emplace_back(0);
    sort(divs.begin(), divs.end());
    divs.erase(unique(divs.begin(), divs.end()), divs.end());

    dp[0][0] = 1;
    for(int i=0; i<N; i++) {
        for(int j=0; j<divs.size(); j++) {
            if(dp[i][j] == 0) continue;
            // 使わない
            dp[i+1][j] += dp[i][j];

            // 使う
            int g = gcd(divs[j], A[i]);
            int k = lower_bound(divs.begin(), divs.end(), g) - divs.begin();
            dp[i+1][k] += dp[i][j];
        }
    }
    cout << dp[N][1] << endl;
    return 0;
}
0