結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー kyo1kyo1
提出日時 2022-02-09 07:06:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,373 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 214,672 KB
実行使用メモリ 13,812 KB
最終ジャッジ日時 2023-09-06 09:56:44
合計ジャッジ時間 3,913 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 35 ms
6,420 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 86 ms
4,948 KB
testcase_13 AC 13 ms
4,380 KB
testcase_14 AC 31 ms
4,444 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 43 ms
7,544 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 85 ms
5,000 KB
testcase_19 AC 47 ms
4,376 KB
testcase_20 AC 137 ms
13,812 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());
    map<int, int> index;
    for (int i = 0; i < (int)divisor.size(); i++) {
      index[divisor[i]] = i;
    }
    vector<int64_t> C(2000, 0), D(2000, 0);
    for (const auto& e : A) {
      if (index.find(gcd(e, K)) != index.end()) C[index[gcd(e, K)]]++;
    }
    for (const auto& e : B) {
      if (index.find(gcd(e, K)) != index.end()) D[index[gcd(e, K)]]++;
    }
    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