結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 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 2 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,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 36 ms
6,564 KB
testcase_11 AC 18 ms
4,380 KB
testcase_12 TLE -
testcase_13 AC 12 ms
4,380 KB
testcase_14 AC 31 ms
4,380 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 44 ms
7,600 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 TLE -
testcase_19 AC 1,505 ms
4,376 KB
testcase_20 AC 140 ms
14,220 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;
    divisor.emplace_back(1);
    divisor.emplace_back(K);
    for (int 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());
    vector<int> cnt(divisor.size(), 0);
    for (const auto& e : A) {
      for (int i = 0; i < (int)divisor.size(); i++) {
        if (e % divisor[i] == 0) {
          cnt[i]++;
          break;
        }
      }
    }
    int64_t res = 0;
    for (const auto& e : B) {
      for (int i = 0; i < (int)divisor.size(); i++) {
        if ((e * divisor[i]) % K == 0) res += cnt[i];
      }
    }
    cout << res << '\n';
  }
  return 0;
}
0