結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー chocoruskchocorusk
提出日時 2020-02-15 04:44:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,281 bytes
コンパイル時間 1,091 ms
コンパイル使用メモリ 119,980 KB
実行使用メモリ 5,420 KB
最終ジャッジ日時 2023-08-10 03:08:56
合計ジャッジ時間 2,911 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 37 ms
4,420 KB
testcase_11 AC 41 ms
4,472 KB
testcase_12 WA -
testcase_13 AC 27 ms
4,380 KB
testcase_14 AC 66 ms
4,656 KB
testcase_15 AC 37 ms
4,376 KB
testcase_16 AC 45 ms
4,448 KB
testcase_17 AC 30 ms
4,504 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 112 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
	int n, m;ll k;
	cin>>n>>m>>k;
	char op; cin>>op;
	ll a[100001], b[100001];
	for(int i=0; i<m; i++) cin>>b[i], b[i]%=k;
	for(int i=0; i<n; i++){
		cin>>a[i];a[i]%=k;
	}
	if(op=='+'){
		ll ans=0;
		sort(b, b+m);
		for(int i=0; i<n; i++){
			int j=lower_bound(b, b+m, (k-a[i])%k)-b;
			int l=upper_bound(b, b+m, (k-a[i])%k)-b;
			ans+=l-j;
		}
		cout<<ans<<endl;
		return 0;
	}
	map<int, ll> mp1, mp2;
	for(int i=0; i<n; i++){
		a[i]=gcd(a[i], k);
		mp1[a[i]]++;
	}
	for(int i=0; i<m; i++){
		b[i]=gcd(b[i], k);
		mp2[b[i]]++;
	}
	ll ans=0;
	for(auto p:mp1){
		for(auto q:mp2){
			if(p.first*q.first%k==0) ans+=p.second*q.second;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0