結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2020-02-15 02:10:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 304 ms / 2,000 ms |
コード長 | 1,442 bytes |
コンパイル時間 | 1,396 ms |
コンパイル使用メモリ | 118,608 KB |
最終ジャッジ日時 | 2025-01-09 00:40:51 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
#include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <deque> #include <queue> #include <array> #include <set> #include <map> #include <cmath> #include <complex> #include <algorithm> #include <numeric> #include <utility> #include <tuple> #include <bitset> #include <cstdint> #include <cassert> #include <random> #include <iterator> using namespace std; using i64 = int64_t; using i32 = int32_t; i64 gcd(i64 x, i64 y) { while (y > 0) { x %= y; swap(x, y); } return x; } int main() { i64 n, m, k; char op; cin >> n >> m >> k >> op; vector<i64> a(n), b(m); for (int i = 0; i < m; ++i) cin >> b[i]; for (int i = 0; i < n; ++i) cin >> a[i]; i64 ans = 0; if (op == '+') { map<i64, i64> ma, mb; for (i64 x : a) ma[x % k]++; for (i64 x : b) mb[x % k]++; for (auto p : ma) { i64 x, c; tie(x, c) = p; ans += c * mb[(k - x) % k]; } } else { map<i64, i64> ma, mb; for (i64 x : a) ma[gcd(x, k)]++; for (i64 x : b) mb[gcd(x, k)]++; for (auto p : ma) { i64 x, c; tie(x, c) = p; for (auto p : mb) { i64 y, d; tie(y, d) = p; if (x * y % k == 0) { ans += c * d; } } } } cout << ans << endl; return 0; }