結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 jupirojupiro
提出日時 2020-03-11 21:14:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,140 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 127,324 KB
実行使用メモリ 379,264 KB
最終ジャッジ日時 2024-04-27 21:45:08
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 35 ms
36,660 KB
testcase_11 AC 36 ms
6,944 KB
testcase_12 AC 131 ms
6,944 KB
testcase_13 AC 23 ms
6,944 KB
testcase_14 AC 39 ms
6,944 KB
testcase_15 AC 26 ms
6,944 KB
testcase_16 AC 218 ms
379,264 KB
testcase_17 AC 21 ms
6,940 KB
testcase_18 AC 131 ms
6,940 KB
testcase_19 AC 46 ms
6,944 KB
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll gcd(ll x, ll y)
{
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, M, K; cin >> N >> M >> K;
	char op; cin >> op;
	vector<int> b(M); for (int i = 0; i < M; i++) cin >> b[i];
	vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i];
	if (op == '+') {
		vector<int> cnt(K);
		for (ll i = 0; i < N; i++) cnt[a[i] % K]++;
		ll res = 0;
		for (ll i = 0; i < M; i++) {
			if (b[i] % K == 0) res += cnt[0];
			else {
				res += cnt[K - b[i] % K];
			}
		}
		cout << res << endl;
	}
	else {
		map<int, int> mp1, mp2;
		for (ll i = 0; i < M; i++) mp1[gcd(K, b[i])]++;
		for (ll i = 0; i < N; i++) mp2[gcd(K, a[i])]++;
		vector<pair<int, int>> vp1, vp2;
		for (auto p : mp1) {
			vp1.emplace_back(p.first, p.second);
		}
		mp1.clear();
		for (auto p : mp2) {
			vp2.emplace_back(p.first, p.second);
		}
		mp2.clear();
		ll res = 0;
		for (auto p1 : vp1) {
			for (auto p2 : vp2) {
				if (1LL * p1.first * p2.first % K == 0) {
					res += 1LL * p1.second * p2.second;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0