結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー HaarHaar
提出日時 2020-02-16 03:07:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,386 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 215,776 KB
実行使用メモリ 14,156 KB
最終ジャッジ日時 2023-08-10 03:21:41
合計ジャッジ時間 9,074 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 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,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 42 ms
6,384 KB
testcase_11 AC 27 ms
4,376 KB
testcase_12 TLE -
testcase_13 AC 19 ms
4,380 KB
testcase_14 AC 40 ms
4,380 KB
testcase_15 AC 23 ms
4,376 KB
testcase_16 AC 47 ms
7,524 KB
testcase_17 AC 22 ms
4,376 KB
testcase_18 TLE -
testcase_19 AC 914 ms
5,680 KB
testcase_20 AC 198 ms
14,156 KB
権限があれば一括ダウンロードができます

ソースコード

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