結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー okok
提出日時 2020-02-14 22:46:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,566 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 117,664 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-27 19:59:28
合計ジャッジ時間 8,859 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 40 ms
7,680 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 TLE -
testcase_13 AC 17 ms
6,940 KB
testcase_14 AC 34 ms
6,940 KB
testcase_15 AC 19 ms
6,940 KB
testcase_16 AC 51 ms
8,704 KB
testcase_17 AC 18 ms
6,944 KB
testcase_18 TLE -
testcase_19 AC 936 ms
6,940 KB
testcase_20 AC 188 ms
17,280 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() >= 1500) 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];
	}
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		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;
	}
	sort(AAK.begin(), AAK.end());
	
	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;
				for(int j = 0; j < ddk.size(); j++){
					if(ttb%ddk[j]) continue;
					// con += AK[K/ddk[j]];
					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