結果

問題 No.917 Make One With GCD
ユーザー monolithmonolith
提出日時 2019-10-25 23:17:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 861 ms / 2,000 ms
コード長 1,329 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 101,336 KB
実行使用メモリ 5,184 KB
最終ジャッジ日時 2023-09-06 16:41:17
合計ジャッジ時間 14,198 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 861 ms
4,912 KB
testcase_01 AC 20 ms
5,032 KB
testcase_02 AC 20 ms
4,996 KB
testcase_03 AC 27 ms
4,964 KB
testcase_04 AC 23 ms
4,900 KB
testcase_05 AC 50 ms
4,912 KB
testcase_06 AC 714 ms
4,900 KB
testcase_07 AC 390 ms
4,916 KB
testcase_08 AC 149 ms
5,184 KB
testcase_09 AC 817 ms
4,980 KB
testcase_10 AC 832 ms
4,936 KB
testcase_11 AC 820 ms
4,944 KB
testcase_12 AC 827 ms
4,920 KB
testcase_13 AC 698 ms
4,932 KB
testcase_14 AC 754 ms
4,984 KB
testcase_15 AC 729 ms
4,888 KB
testcase_16 AC 697 ms
4,920 KB
testcase_17 AC 92 ms
4,920 KB
testcase_18 AC 342 ms
4,900 KB
testcase_19 AC 40 ms
4,928 KB
testcase_20 AC 129 ms
4,884 KB
testcase_21 AC 249 ms
5,092 KB
testcase_22 AC 182 ms
5,184 KB
testcase_23 AC 409 ms
5,048 KB
testcase_24 AC 271 ms
5,068 KB
testcase_25 AC 408 ms
4,896 KB
testcase_26 AC 72 ms
5,000 KB
testcase_27 AC 9 ms
4,884 KB
testcase_28 AC 8 ms
4,980 KB
testcase_29 AC 14 ms
5,180 KB
testcase_30 AC 162 ms
4,924 KB
testcase_31 AC 36 ms
4,980 KB
testcase_32 AC 70 ms
4,900 KB
testcase_33 AC 54 ms
4,936 KB
testcase_34 AC 35 ms
4,980 KB
testcase_35 AC 85 ms
4,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[100001];

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	int N;
	cin >> N;
	map<long long int, int> m;
	for(int i = 0; i < N; i++){
		long long int A;
		cin >> A;
		long long int DP_[100001] = {};
		for(int j = 1; j <= 100000; j++){
			DP_[GCD(A, j)] += DP[j];
		}
		map<long long int, int> m2;
		for(P p : m){
			long long int G = GCD(A, p.first);
			if(G <= 100000){
				DP_[G] += p.second;
			}else{
				m2[G] += p.second;
			}
		}
		for(int j = 0; j <= 100000; j++){
			DP[j] += DP_[j];
		}
		for(P p : m2){
			m[p.first] += p.second;
		}
		if(A < 100000){
			DP[A] += 1;
		}else{
			m[A] += 1;
		}
	}
	cout << DP[1] << endl;
	return 0;
}
0