結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-14 22:02:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 2,000 ms |
| コード長 | 1,510 bytes |
| コンパイル時間 | 2,177 ms |
| コンパイル使用メモリ | 187,252 KB |
| 実行使用メモリ | 17,152 KB |
| 最終ジャッジ日時 | 2024-11-16 00:41:43 |
| 合計ジャッジ時間 | 3,542 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T>
vector<T> divisor(T n) {
vector<T> res;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.emplace_back(i);
if (i != n / i) res.emplace_back(n / i);
}
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
ll K;
cin >> K;
char op;
cin >> op;
vector<ll> b(m);
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
sort(b.begin(), b.end());
vector<ll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
if (op == '+') {
map<ll, int> cntb;
for (int i = 0; i < m; ++i) {
cntb[b[i] % K]++;
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += cntb[(K - a[i] % K) % K];
}
cout << ans << "\n";
} else {
map<ll, ll> cntb;
for (int i = 0; i < m; ++i) {
cntb[__gcd(b[i], K)]++;
}
map<ll, ll> cnta;
for (int i = 0; i < n; ++i) {
cnta[__gcd(a[i], K)]++;
}
vector<ll> ds = divisor(K);
ll ans = 0;
//cerr << ans << endl;
for (ll x : ds) {
for (ll y : ds) {
if (x * y % K != 0) continue;
ans += cnta[x] * cntb[y];
}
}
cout << ans << "\n";
}
return 0;
}