結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー okok
提出日時 2020-02-14 22:29:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,949 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 109,340 KB
実行使用メモリ 14,068 KB
最終ジャッジ日時 2023-08-10 02:08:35
合計ジャッジ時間 7,541 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 28 ms
6,320 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 1,960 ms
9,536 KB
testcase_13 AC 18 ms
4,376 KB
testcase_14 AC 27 ms
4,380 KB
testcase_15 AC 19 ms
4,380 KB
testcase_16 AC 36 ms
6,956 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 TLE -
testcase_19 AC 941 ms
5,228 KB
testcase_20 AC 107 ms
14,068 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;
	unordered_map<int,int> aa, dk, AK;
	vector<pair<int,int>> AA, DK;
	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);
		}
	}
	
	
	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];
		// B[i] %= K;
	}
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		// A[i] %= K;
		
		aa[A[i]%K]++;
		
		int ta = A[i], tta = 1;
		
		// AK[A[i]]
		
		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]++;
	}
	
	
	
	
	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;
					}
				}
				
				for(int j = 0; j < ddk.size(); j++){
					if(ttb%ddk[j]) continue;
					con += AK[K/ddk[j]];
				}
			}
			
		}
	}
	
	cout<<con<<endl;
	
	return 0;
}
0