結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー furafura
提出日時 2020-02-18 11:28:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 2,664 ms
コンパイル使用メモリ 211,152 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 21:02:33
合計ジャッジ時間 3,171 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 21 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 98 ms
6,940 KB
testcase_13 AC 15 ms
6,940 KB
testcase_14 AC 35 ms
6,940 KB
testcase_15 AC 18 ms
6,944 KB
testcase_16 AC 23 ms
6,944 KB
testcase_17 AC 17 ms
6,944 KB
testcase_18 AC 95 ms
6,940 KB
testcase_19 AC 54 ms
6,940 KB
testcase_20 AC 47 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T> T gcd(const T& a,const T& b){ return b==0?a:gcd(b,a%b); }

vector<long long> divisors(long long a){
	vector<long long> res;
	for(long long i=1;i*i<=a;i++) if(a%i==0) {
		res.emplace_back(i);
		if(i*i<a) res.emplace_back(a/i);
	}
	sort(res.begin(),res.end());
	return res;
}

int main(){
	int n,m;
	lint k;
	char op;
	cin>>n>>m>>k>>op;
	vector<lint> b(m),a(n);
	rep(j,m) scanf("%lld",&b[j]), b[j]%=k;
	rep(i,n) scanf("%lld",&a[i]), a[i]%=k;

	sort(b.begin(),b.end());

	lint ans=0;
	if(op=='+'){
		rep(i,n){
			auto p=equal_range(b.begin(),b.end(),(k-a[i])%k);
			ans+=p.second-p.first;
		}
	}
	else{
		auto D=divisors(k);
		vector<int> cnt1(D.size()),cnt2(D.size());
		rep(i,n){
			a[i]=gcd(a[i],k);
			cnt1[lower_bound(D.begin(),D.end(),a[i])-D.begin()]++;
		}
		rep(j,m){
			b[j]=gcd(b[j],k);
			cnt2[lower_bound(D.begin(),D.end(),b[j])-D.begin()]++;
		}
		rep(i,D.size()) rep(j,D.size()) if(D[i]*D[j]%k==0) ans+=cnt1[i]*cnt2[j];
	}
	printf("%lld\n",ans);

	return 0;
}
0