結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー okok
提出日時 2020-02-14 22:57:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 3,001 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 114,168 KB
実行使用メモリ 17,080 KB
最終ジャッジ日時 2023-08-10 02:24:22
合計ジャッジ時間 3,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 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 2 ms
4,376 KB
testcase_10 AC 44 ms
7,496 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 220 ms
10,672 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 35 ms
4,428 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 54 ms
8,572 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 AC 221 ms
10,652 KB
testcase_19 AC 63 ms
5,700 KB
testcase_20 AC 187 ms
17,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, M, K;
	vector<int> A, B, a, b;
	vector<int> ak;
	vector<int> ddk;
	map<int,int> aa, dk, AK;
	vector<pair<int,int>> AA, DK, AAK;
	string op;
	int con = 0;
	cin>>N>>M>>K;
	
	cin>>op;
	
	B.resize(M);
	A.resize(N);
	
	int k = K;
	
	for(int i = 1; i * i <= k; i++){
		if(i * i == k) {
			ddk.push_back(i);
		}else if(K%i == 0) {
			
			ddk.push_back(i);
			ddk.push_back(K/i);
		}
	}
	// if(K > 1'000'000'000) exit(2);
	// ddk.size();
	// if(ddk.size() >= 1250) exit(2);
	
	for(int i = 2; i * i <= k; i++){
		while(k%i == 0){
			k /= i;
			dk[i]++;
		}
	}
	
	if(k != 1) dk[k]++;
	
	for(pair<int,int> p : dk){
		DK.push_back(p);
	}
	
	ak.resize(DK.size());
	
	for(int i = 0; i < M; i++){
		cin>>B[i];
			
		if(B[i] > 1'000'000'000) exit(2);
	}
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		if(A[i] > 1'000'000'000) exit(2);
		aa[A[i]%K]++;
		
		int ta = A[i], tta = 1;
		
		for(int j = 0; j < DK.size(); j++){
			for(int z = 0; ta % DK[j].first == 0 && z < DK[j].second; z++){
				ta /= DK[j].first;
				tta *= DK[j].first;
			}
		}
		AK[tta]++;
	}
	
	
	for(pair<int,int> p : AK){
		AAK.push_back(p);
		// cout<<p.first<<" "<<p.second<<endl;
	}
	// for(pair<int,int> p : AK){
	
	for(int j = 0; j < ddk.size(); j++){
		int sum = 0;
		for(int i = 0; i < AAK.size(); i++){
			if(ddk[j]%(K/AAK[i].first)) continue;
			sum += AAK[i].second;
		}
		// cout<<ddk[j]<<" sum "<<sum<<endl;
		AK[ddk[j]] = sum;
	}
	sort(AAK.begin(), AAK.end());
	
	for(int i = 0; i < AAK.size(); i++){
	}
	if(op == "+") {
		for(int i = 0; i < M; i++){
			con += aa[(K-B[i]%K)%K];
			
		}
	} else {
		for(int i = 0; i < M; i++){
			if(B[i] == 0) con += N;
			else {
				int ttb = 1, tb = B[i];
				for(int j = 0; j < DK.size(); j++){
					for(int z = 0; tb % DK[j].first == 0 && z < DK[j].second; z++){
						tb /= DK[j].first;
						ttb *= DK[j].first;
					}
				}
				// cout<<"i = "<<i<<" B = "<<B[i]<<endl;
				con += AK[ttb];
				/*
				for(int j = 0; j < ddk.size(); j++){
					if(ttb%ddk[j]) continue;
					// con += AK[K/ddk[j]];
					
					// continue;
					pair<int,int> key = {K/ddk[j],-INF};
					auto hoge = lower_bound(AAK.begin(), AAK.end(), key);
					// con +=  (*lower_bound(AAK.begin(), AAK.end(), key)).second;
					// cout<<"ddk "<<ddk[j]<<" "<<key.first<<endl;
					if(hoge != AAK.end() && (*hoge).first == key.first) {
						con += (*hoge).second;
						// cout<<(*hoge).first<<" "<<(*hoge).second<<endl;
					}
				}
				*/
				// cout<<"con "<<con<<endl;
				// cout<<endl;
			}
			
		}
	}
	
	cout<<con<<endl;
	
	return 0;
}
0