結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-11 21:11:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,091 bytes |
| コンパイル時間 | 1,302 ms |
| コンパイル使用メモリ | 126,584 KB |
| 実行使用メモリ | 755,512 KB |
| 最終ジャッジ日時 | 2024-11-16 03:47:43 |
| 合計ジャッジ時間 | 3,347 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 6 RE * 1 MLE * 1 |
ソースコード
#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関連注意!!!!!!!!!!!!
*/
}