結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー kyo1kyo1
提出日時 2022-02-09 07:11:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,355 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 214,456 KB
実行使用メモリ 13,848 KB
最終ジャッジ日時 2023-09-06 10:07:19
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 37 ms
6,408 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 73 ms
4,580 KB
testcase_13 AC 14 ms
4,376 KB
testcase_14 AC 30 ms
4,380 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 45 ms
7,592 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 72 ms
4,824 KB
testcase_19 AC 44 ms
4,376 KB
testcase_20 AC 144 ms
13,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M, K;
  cin >> N >> M >> K;
  char op;
  cin >> op;
  vector<int64_t> A(N), B(M);
  for (auto&& e : B) {
    cin >> e;
  }
  for (auto&& e : A) {
    cin >> e;
  }
  if (op == '+') {
    map<int, int> mp;
    for (const auto& e : A) {
      mp[e % K]++;
    }
    int64_t res = 0;
    for (const auto& e : B) {
      res += mp[(2 * K - (e % K)) % K];
    }
    cout << res << '\n';
  } else {
    vector<int64_t> divisor;
    for (int i = 1; i * i < K + 1; i++) {
      if (K % i == 0) {
        divisor.emplace_back(i);
        if (i * i != K) divisor.emplace_back(K / i);
      }
    }
    sort(divisor.begin(), divisor.end());
    vector<int64_t> C(divisor.size(), 0), D(divisor.size(), 0);
    for (const auto& e : A) {
      const int p = lower_bound(divisor.begin(), divisor.end(), gcd(e, K)) - divisor.begin();
      C[p]++;
    }
    for (const auto& e : B) {
      const int p = lower_bound(divisor.begin(), divisor.end(), gcd(e, K)) - divisor.begin();
      D[p]++;
    }
    int64_t res = 0;
    for (int i = 0; i < (int)divisor.size(); i++) {
      for (int j = 0; j < (int)divisor.size(); j++) {
        if ((divisor[i] * divisor[j]) % K == 0) res += C[i] * D[j];
      }
    }
    cout << res << '\n';
  }
  return 0;
}
0