結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー CELICACELICA
提出日時 2020-10-14 09:02:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 1,733 ms
コンパイル使用メモリ 177,424 KB
実行使用メモリ 10,132 KB
最終ジャッジ日時 2023-09-28 00:29:57
合計ジャッジ時間 3,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 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 34 ms
6,196 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 AC 107 ms
4,380 KB
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 34 ms
6,004 KB
testcase_17 AC 16 ms
4,376 KB
testcase_18 AC 107 ms
4,376 KB
testcase_19 AC 37 ms
4,376 KB
testcase_20 AC 110 ms
10,132 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

template <class T>
T gcd(T a, T b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ll n, m, k;
	cin >> n >> m >> k;
	string op;
	cin >> op;

	vector<ll> b(m);
	for (auto&& it : b)
		cin >> it;

	ll res{ 0 };
	if (op == "+")
	{
		map<ll, ll> mb;
		for (auto&& it : b)
			++mb[it % k];
		for (int i = 0; i < n; ++i)
		{
			ll a;
			cin >> a;
			ll mod = -a % k;
			if (mod < 0)
				mod += k;
			if (mb.count(mod))
				res += mb[mod];
		}
	}
	else
	{
		map<ll, ll> gcdb, gcda;
		for (auto&& it : b)
			++gcdb[gcd(it, k)];

		for (int i = 0; i < n; ++i)
		{
			ll a;
			cin >> a;
			++gcda[gcd(a, k)];
		}

		for (const auto& itb : gcdb)
			for (const auto& ita : gcda)
				if ((ita.first * itb.first) % k == 0)
					res += ita.second * itb.second;
	}

	cout << res << "\n";

	return 0;
}
0