結果

問題 No.1036 Make One With GCD 2
ユーザー 👑 kmjpkmjp
提出日時 2020-05-01 23:33:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 476 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 2,694 ms
コンパイル使用メモリ 207,356 KB
実行使用メモリ 7,488 KB
最終ジャッジ日時 2023-10-14 20:27:16
合計ジャッジ時間 13,129 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
7,248 KB
testcase_01 AC 161 ms
7,488 KB
testcase_02 AC 103 ms
7,252 KB
testcase_03 AC 14 ms
4,776 KB
testcase_04 AC 23 ms
5,920 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 51 ms
5,000 KB
testcase_08 AC 42 ms
4,716 KB
testcase_09 AC 314 ms
7,160 KB
testcase_10 AC 293 ms
6,960 KB
testcase_11 AC 320 ms
7,260 KB
testcase_12 AC 296 ms
6,996 KB
testcase_13 AC 470 ms
7,096 KB
testcase_14 AC 476 ms
7,128 KB
testcase_15 AC 447 ms
6,892 KB
testcase_16 AC 451 ms
6,936 KB
testcase_17 AC 465 ms
7,028 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 440 ms
6,836 KB
testcase_23 AC 326 ms
5,908 KB
testcase_24 AC 459 ms
7,000 KB
testcase_25 AC 419 ms
6,672 KB
testcase_26 AC 433 ms
6,800 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 1 ms
4,352 KB
testcase_29 AC 2 ms
4,352 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 1 ms
4,352 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,348 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 247 ms
7,376 KB
testcase_39 AC 103 ms
7,488 KB
testcase_40 AC 324 ms
5,916 KB
testcase_41 AC 104 ms
7,264 KB
testcase_42 AC 104 ms
7,272 KB
testcase_43 AC 103 ms
7,340 KB
testcase_44 AC 104 ms
7,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[505050];
map<ll,int> M,M2;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll ret=0;
	FOR(i,N) {
		cin>>A[i];
		
		M[A[i]]++;
		if(i&&A[i]==A[i-1]) {
			FORR(m,M) {
				if(m.first==1) ret+=m.second;
			}
		}
		else {
			FORR(m,M) {
				ll x=__gcd(m.first,A[i]);
				if(x==1) ret+=m.second;
				M2[x]+=m.second;
			}
			swap(M,M2);
			M2.clear();
		}
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0