結果

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

ソースコード

diff #

#include <bits/stdc++.h>

std::vector<std::int64_t> divisor_list(std::int64_t n){
  std::vector<std::int64_t> temp, ret;

  {
    std::int64_t i;
    for(i = 1LL; i*i < n; ++i){
      if(n%i == 0){
        temp.push_back(n / i);
        ret.push_back(i);
      }
    }
    if(i*i == n) ret.push_back(i);
  }

  std::reverse(temp.begin(), temp.end());
  ret.insert(ret.end(), temp.begin(), temp.end());
  
  return ret;
}


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];

  std::sort(A.begin(), A.end());
  std::sort(B.begin(), B.end());

  std::map<int, int> count;
  for(auto x : B) count[x % K] += 1;

  auto divs = divisor_list(K);
  std::map<int, int> count_div;
  for(auto x : B){
    for(auto d : divs){
      if(x % d == 0){
        count_div[d] += 1;
      }
    }
  }
  

  int64_t ans = 0;

  if(op == '+'){
    for(auto x : A){
      if(x % K == 0){
        ans += count[0];
      }else{
        ans += count[K - (x % K)];
      }
    }
  }else{
    for(auto x : A){
      if(x % K == 0){
        ans += M;
      }else{
        int64_t t = K / (std::gcd(K, x));
        ans += count_div[t];
      }
    }
  }

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