結果

問題 No.1036 Make One With GCD 2
ユーザー kotatsugamekotatsugame
提出日時 2020-04-24 21:51:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 619 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 75,504 KB
実行使用メモリ 12,896 KB
最終ジャッジ日時 2023-10-14 19:16:10
合計ジャッジ時間 15,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 318 ms
4,352 KB
testcase_01 AC 225 ms
4,352 KB
testcase_02 AC 337 ms
11,832 KB
testcase_03 AC 32 ms
4,352 KB
testcase_04 AC 55 ms
4,348 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 90 ms
4,352 KB
testcase_08 AC 74 ms
4,348 KB
testcase_09 AC 360 ms
4,348 KB
testcase_10 AC 334 ms
4,348 KB
testcase_11 AC 366 ms
4,348 KB
testcase_12 AC 339 ms
4,352 KB
testcase_13 AC 611 ms
4,348 KB
testcase_14 AC 619 ms
4,348 KB
testcase_15 AC 579 ms
4,352 KB
testcase_16 AC 587 ms
4,352 KB
testcase_17 AC 604 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 572 ms
4,352 KB
testcase_23 AC 420 ms
4,348 KB
testcase_24 AC 596 ms
4,352 KB
testcase_25 AC 540 ms
4,348 KB
testcase_26 AC 563 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 328 ms
12,896 KB
testcase_39 AC 329 ms
4,352 KB
testcase_40 AC 420 ms
4,348 KB
testcase_41 AC 502 ms
4,352 KB
testcase_42 AC 503 ms
4,348 KB
testcase_43 AC 472 ms
8,356 KB
testcase_44 AC 490 ms
5,564 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:40:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   40 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
vector<pair<long,long> >had,til;
void psh(long X)
{
	if(til.empty())
	{
		til.push_back(make_pair(X,X));
		return;
	}
	long pre=til.back().first;
	til.push_back(make_pair(gcd(pre,X),X));
}
void pp()
{
	if(had.empty())
	{
		had=til;
		reverse(had.begin(),had.end());
		til.clear();
		long cum=0;
		for(int i=0;i<had.size();i++)
		{
			cum=gcd(cum,had[i].second);
			had[i].first=cum;
		}
	}
	had.pop_back();
}
long query()
{
	long L=had.empty()?0L:had.back().first;
	long R=til.empty()?0L:til.back().first;
	return gcd(L,R);
}
long N;
main()
{
	cin>>N;
	long ans=N*(N+1)/2;
	for(int i=0;i<N;i++)
	{
		long A;cin>>A;psh(A);
		while(query()==1)pp();
		ans-=had.size()+til.size();
	}
	cout<<ans<<endl;
}
0