結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー kyo1kyo1
提出日時 2022-02-09 06:48:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,251 bytes
コンパイル時間 3,077 ms
コンパイル使用メモリ 213,844 KB
実行使用メモリ 14,176 KB
最終ジャッジ日時 2023-09-06 09:29:59
合計ジャッジ時間 11,552 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 35 ms
6,508 KB
testcase_11 AC 26 ms
4,376 KB
testcase_12 TLE -
testcase_13 WA -
testcase_14 AC 37 ms
4,380 KB
testcase_15 AC 21 ms
4,376 KB
testcase_16 AC 43 ms
7,540 KB
testcase_17 AC 18 ms
4,376 KB
testcase_18 TLE -
testcase_19 AC 1,524 ms
4,376 KB
testcase_20 AC 93 ms
14,176 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;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  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;
    divisor.emplace_back(1);
    for (int64_t i = 2; 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());
    reverse(divisor.begin(), divisor.end());
    map<int, int> mp;
    for (const auto& e : A) {
      for (const auto& f : divisor) {
        if (e % f == 0) {
          mp[f]++;
          break;
        }
      }
    }
    int64_t res = 0;
    for (const auto& e : B) {
      for (const auto& f : divisor) {
        if ((e * f) % K == 0) res += mp[f];
      }
    }
    cout << res << '\n';
  }
  return 0;
}
0