結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー Haar
提出日時 2020-02-16 03:12:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 202,760 KB
最終ジャッジ日時 2025-01-09 00:53:23
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(0);
  
  int N, M, K; std::cin >> N >> M >> K;
  char op; std::cin >> op;
  std::vector<int64_t> A(N), B(M);
  for(int i = 0; i < M; ++i) std::cin >> B[i];
  for(int i = 0; i < N; ++i) std::cin >> A[i];

  int64_t ans = 0;

  if(op == '+'){
    std::map<int, int> count;
    for(auto x : B) count[x % K] += 1;
    
    for(auto x : A){
      if(x % K == 0){
        ans += count[0];
      }else{
        ans += count[K - (x % K)];
      }
    }
  }else{
    std::map<int, int> ga, gb;

    for(auto x : A) ga[std::gcd(x, K)] += 1;
    for(auto x : B) gb[std::gcd(x, K)] += 1;

    for(auto &[x,a] : ga){
      for(auto &[y,b] : gb){
        if(((int64_t)x*y) % K == 0){
          ans += (int64_t)a * b;
        }
      }
    }
  }

  std::cout << ans << std::endl;
  
  return 0;
}
0