結果

問題 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,466 ms
コンパイル使用メモリ 209,740 KB
実行使用メモリ 13,776 KB
最終ジャッジ日時 2023-08-10 03:20:49
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 35 ms
6,428 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 30 ms
4,376 KB
testcase_15 AC 15 ms
4,384 KB
testcase_16 AC 44 ms
7,520 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 137 ms
13,776 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