結果
| 問題 |
No.917 Make One With GCD
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-10-29 19:21:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 1,643 bytes |
| コンパイル時間 | 848 ms |
| コンパイル使用メモリ | 87,368 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 11:10:20 |
| 合計ジャッジ時間 | 1,652 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:61:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 917.cc: No.917 Make One With GCD - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 50;
const int MAX_M = 1024;
/* typedef */
typedef long long ll;
/* global variables */
int as[MAX_N], dvs[MAX_N][MAX_M], dms[MAX_N];
ll dp[MAX_N][MAX_M];
/* subroutines */
template <typename T>
T gcd(T m, T n) { // m > 0, n > 0
if (m < n) swap(m, n);
while (n > 0) {
T r = m % n;
m = n;
n = r;
}
return m;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", as + i);
dms[i] = 0;
for (int p = 1; p * p <= as[i]; p++)
if (as[i] % p == 0) {
dvs[i][dms[i]++] = p;
int q = as[i] / p;
if (q != p) dvs[i][dms[i]++] = q;
}
sort(dvs[i], dvs[i] + dms[i]);
//printf("dms[%d]=%d\n", i, dms[i]);
}
for (int i = 0; i < n; i++) {
int ai = as[i], dmi = dms[i], *dvi = dvs[i];
ll *dpi = dp[i];
dpi[dmi - 1] = 1;
for (int j = i - 1; j >= 0; j--) {
int dmj = dms[j], *dvj = dvs[j];
ll *dpj = dp[j];
for (int k = 0; k < dmj; k++)
if (dpj[k] > 0) {
int g = gcd(dvj[k], ai);
int h = lower_bound(dvi, dvi + dmi, g) - dvi;
dpi[h] += dpj[k];
}
}
}
ll sum = 0;
for (int i = 0; i < n; i++) sum += dp[i][0];
printf("%lld\n", sum);
return 0;
}
tnakao0123