結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2020-09-24 19:24:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 206 ms / 2,000 ms |
コード長 | 1,357 bytes |
コンパイル時間 | 1,389 ms |
コンパイル使用メモリ | 88,132 KB |
最終ジャッジ日時 | 2025-01-14 20:04:36 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include <iostream> #include <numeric> #include <vector> #include <map> using lint = long long; void solve() { int n, m, k; char op; std::cin >> n >> m >> k >> op; if (op == '+') { std::map<int, lint> cnt; while (m--) { int x; std::cin >> x; x %= k; if (!cnt.count(x)) cnt[x] = 0; ++cnt[x]; } lint ans = 0; while (n--) { int x; std::cin >> x; x = (k - x % k) % k; if (cnt.count(x)) ans += cnt[x]; } std::cout << ans << "\n"; } else { std::map<lint, lint> acnt, bcnt; while (m--) { int x; std::cin >> x; x = std::gcd(x, k); if (!bcnt.count(x)) bcnt[x] = 0; ++bcnt[x]; } while (n--) { int x; std::cin >> x; x = std::gcd(x, k); if (!acnt.count(x)) acnt[x] = 0; ++acnt[x]; } lint ans = 0; for (auto [p1, c1] : acnt) { for (auto [p2, c2] : bcnt) { if (p1 * p2 % k == 0) ans += c1 * c2; } } std::cout << ans << "\n"; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }