結果
問題 |
No.990 N×Mマス計算(Kの倍数)
|
ユーザー |
![]() |
提出日時 | 2020-10-14 09:02:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 970 bytes |
コンパイル時間 | 1,565 ms |
コンパイル使用メモリ | 178,456 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2024-07-20 19:00:22 |
合計ジャッジ時間 | 2,857 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#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; }