結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | fine |
提出日時 | 2020-02-14 22:02:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 117 ms / 2,000 ms |
コード長 | 1,510 bytes |
コンパイル時間 | 1,958 ms |
コンパイル使用メモリ | 184,560 KB |
実行使用メモリ | 16,896 KB |
最終ジャッジ日時 | 2023-08-10 01:56:20 |
合計ジャッジ時間 | 3,375 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 36 ms
7,372 KB |
testcase_11 | AC | 24 ms
4,376 KB |
testcase_12 | AC | 117 ms
4,968 KB |
testcase_13 | AC | 17 ms
4,376 KB |
testcase_14 | AC | 39 ms
4,380 KB |
testcase_15 | AC | 21 ms
4,376 KB |
testcase_16 | AC | 45 ms
8,548 KB |
testcase_17 | AC | 17 ms
4,376 KB |
testcase_18 | AC | 116 ms
4,848 KB |
testcase_19 | AC | 65 ms
4,376 KB |
testcase_20 | AC | 95 ms
16,896 KB |
ソースコード
#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; }