結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー HaarHaar
提出日時 2020-02-16 03:10:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 858 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 212,596 KB
実行使用メモリ 14,208 KB
最終ジャッジ日時 2024-04-27 20:54:06
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 32 ms
6,940 KB
testcase_11 AC 19 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 12 ms
6,940 KB
testcase_14 AC 28 ms
6,944 KB
testcase_15 AC 15 ms
6,944 KB
testcase_16 AC 42 ms
7,680 KB
testcase_17 AC 13 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 113 ms
14,208 KB
権限があれば一括ダウンロードができます

ソースコード

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((x*y) % K == 0){
          ans += (int64_t)a * b;
        }
      }
    }
  }

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