結果

問題 No.917 Make One With GCD
ユーザー tkmst201tkmst201
提出日時 2019-10-26 16:35:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,402 bytes
コンパイル時間 1,818 ms
コンパイル使用メモリ 182,356 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-09-06 16:43:56
合計ジャッジ時間 3,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
9,656 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
5,404 KB
testcase_04 AC 2 ms
5,440 KB
testcase_05 AC 3 ms
9,560 KB
testcase_06 AC 10 ms
9,644 KB
testcase_07 AC 6 ms
9,672 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 7 ms
9,644 KB
testcase_10 AC 7 ms
9,728 KB
testcase_11 AC 7 ms
9,648 KB
testcase_12 AC 8 ms
9,724 KB
testcase_13 AC 7 ms
9,596 KB
testcase_14 AC 7 ms
9,724 KB
testcase_15 AC 6 ms
9,644 KB
testcase_16 AC 6 ms
9,564 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
9,568 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
5,404 KB
testcase_21 AC 4 ms
7,580 KB
testcase_22 AC 2 ms
5,424 KB
testcase_23 AC 4 ms
9,720 KB
testcase_24 AC 3 ms
7,524 KB
testcase_25 AC 5 ms
9,632 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

vector<ll> findDivisor(ll n) {
	vector<ll> divisor;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			divisor.push_back(i);
			if (i * i != n) divisor.push_back(n / i);
		}
	}
	sort(ALL(divisor));
	return divisor;
}

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


int N;
int A[50];
ll dp[51][25601];

int main() {
	cin >> N;
	REP(i, N) cin >> A[i];
	map<int, int> mm;
	vector<int> rev;
	REP(i, N) {
		vector<ll> v = findDivisor(A[i]);
		for (ll cur : v) if (mm.find(cur) == mm.end()) {
			int sz = mm.size();
			mm[cur] = sz;
			rev.push_back(cur);
		}
	}
	
	REP(i, N) {
		REP(j, rev.size()) if (dp[i][j]) {
			dp[i + 1][mm[gcd(A[i], rev[j])]] += dp[i][j];
			dp[i + 1][j] += dp[i][j];
		}
		dp[i + 1][mm[A[i]]]++;
	}
	
	cout << dp[N][mm[1]] << endl;
	
	return 0;
}
0