結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー furafura
提出日時 2020-02-14 21:55:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,649 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 3,104 ms
コンパイル使用メモリ 208,064 KB
実行使用メモリ 4,608 KB
最終ジャッジ日時 2023-08-10 01:53:01
合計ジャッジ時間 8,425 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 35 ms
4,380 KB
testcase_11 AC 42 ms
4,380 KB
testcase_12 AC 1,648 ms
4,564 KB
testcase_13 AC 28 ms
4,380 KB
testcase_14 AC 61 ms
4,388 KB
testcase_15 AC 35 ms
4,380 KB
testcase_16 AC 45 ms
4,380 KB
testcase_17 AC 28 ms
4,384 KB
testcase_18 AC 1,649 ms
4,608 KB
testcase_19 AC 938 ms
4,384 KB
testcase_20 AC 101 ms
4,556 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) cin>>b[j], b[j]%=k;
	rep(i,n) cin>>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> cnt(D.size());
		rep(j,m) rep(l,D.size()) if(b[j]%D[l]==0) cnt[l]++;

		rep(i,n){
			ans+=cnt[lower_bound(D.begin(),D.end(),k/gcd(a[i],k))-D.begin()];
		}
	}
	cout<<ans<<'\n';

	return 0;
}
0