結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー kyo1kyo1
提出日時 2022-02-09 07:02:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 876 bytes
コンパイル時間 2,140 ms
コンパイル使用メモリ 208,540 KB
実行使用メモリ 13,788 KB
最終ジャッジ日時 2023-09-06 09:51:56
合計ジャッジ時間 4,350 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 17 ms
4,380 KB
testcase_02 AC 17 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 17 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 17 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 38 ms
6,636 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 RE -
testcase_13 AC 27 ms
4,376 KB
testcase_14 AC 34 ms
4,380 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 45 ms
7,504 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 153 ms
13,788 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> C(2000, 0), D(2000, 0);
    for (const auto& e : A) {
      C[gcd(e, K)]++;
    }
    for (const auto& e : B) {
      D[gcd(e, K)]++;
    }
    int64_t res = 0;
    for (int i = 0; i < 2000; i++) {
      for (int j = 0; j < 2000; j++) {
        if (i * j % K == 0) res += C[i] * D[j];
      }
    }
    cout << res << '\n';
  }
  return 0;
}
0