結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 jupirojupiro
提出日時 2020-03-11 21:11:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,091 bytes
コンパイル時間 1,204 ms
コンパイル使用メモリ 127,168 KB
実行使用メモリ 755,500 KB
最終ジャッジ日時 2024-04-27 21:44:55
合計ジャッジ時間 3,332 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 1 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 37 ms
6,944 KB
testcase_12 AC 135 ms
6,944 KB
testcase_13 AC 24 ms
6,940 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 MLE -
testcase_17 WA -
testcase_18 AC 136 ms
6,940 KB
testcase_19 AC 46 ms
6,940 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<ll> b(M); for (int i = 0; i < M; i++) cin >> b[i];
	vector<ll> a(N); for (int i = 0; i < N; i++) cin >> a[i];
	if (op == '+') {
		vector<ll> cnt(K);
		for (ll i = 0; i < N; i++) cnt[a[i] % K]++;
		ll res = 0;
		for (ll i = 0; i < N; i++) {
			if (b[i] % K == 0) res += cnt[0];
			else {
				res += cnt[K - b[i] % K];
			}
		}
		cout << res << endl;
	}
	else {
		map<ll, ll> 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<ll, ll>> vp1, vp2;
		for (auto p : mp1) {
			vp1.emplace_back(p.first, p.second);
		}
		for (auto p : mp2) {
			vp2.emplace_back(p.first, p.second);
		}
		ll res = 0;
		for (auto p1 : vp1) {
			for (auto p2 : vp2) {
				if (p1.first * p2.first % K == 0) {
					res += p1.second * p2.second;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0