結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー TsubaMukkuTsubaMukku
提出日時 2020-02-15 06:55:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 178,292 KB
実行使用メモリ 13,048 KB
最終ジャッジ日時 2023-08-10 03:09:11
合計ジャッジ時間 3,415 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 35 ms
6,132 KB
testcase_11 AC 15 ms
4,380 KB
testcase_12 AC 95 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 29 ms
4,380 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 44 ms
6,808 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 100 ms
4,376 KB
testcase_19 AC 32 ms
4,380 KB
testcase_20 AC 146 ms
13,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll=long long;

int gcd(int a,int b){
	return a?gcd(b%a,a):b;
}

int main(){cin.tie(0);ios::sync_with_stdio(false);
	int N,M,K;cin>>N>>M>>K;
	string op;cin>>op;
	ll z=0;
	if(op=="+"){
		map<int,int>m;
		for(int i=0;i<M;++i){
			int B;cin>>B;
			++m[B%K];
		}
		for(int i=0;i<N;++i){
			int A;cin>>A;
			z+=m[(K-A%K)%K];
		}
	}else{
		map<ll,ll>ma,mb;
		for(int i=0;i<M;++i){
			int B;cin>>B;
			++mb[gcd(K,B)];
		}
		for(int i=0;i<N;++i){
			int A;cin>>A;
			++ma[gcd(K,A)];
		}
		for(auto a:ma){
			for(auto b:mb){
				if(a.first*b.first%K==0){
					z+=a.second*b.second;
				}
			}
		}
	}
	cout<<z<<"\n";
	return 0;
}
0