結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー SSRSSSRS
提出日時 2021-12-17 03:10:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,509 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 173,008 KB
実行使用メモリ 754,888 KB
最終ジャッジ日時 2023-10-12 03:37:28
合計ジャッジ時間 7,298 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 4 ms
4,868 KB
testcase_10 AC 82 ms
69,432 KB
testcase_11 AC 38 ms
4,352 KB
testcase_12 AC 131 ms
4,348 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 42 ms
4,352 KB
testcase_15 AC 27 ms
4,348 KB
testcase_16 MLE -
testcase_17 AC 20 ms
4,348 KB
testcase_18 AC 131 ms
4,352 KB
testcase_19 AC 65 ms
4,352 KB
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
  if (b == 0){
    return a;
  } else {
    return gcd(b, a % b);
  }
}
int main(){
  int N, M, K;
  cin >> N >> M >> K;
  char op;
  cin >> op;
  vector<int> B(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  if (op == '+'){
    vector<int> cntA(K, 0);
    for (int i = 0; i < N; i++){
      cntA[A[i] % K]++;
    }
    vector<int> cntB(K, 0);
    for (int i = 0; i < M; i++){
      cntB[B[i] % K]++;
    }
    long long ans = 0;
    for (int i = 0; i < K; i++){
      ans += (long long) cntA[i] * cntB[(K - i) % K];
    }
    cout << ans << endl;
  }
  if (op == '*'){
    vector<int> F;
    for (int i = 1; i * i <= K; i++){
      if (K % i == 0){
        F.push_back(i);
        if (i * i < K){
          F.push_back(K / i);
        }
      }
    }
    sort(F.begin(), F.end());
    int c = F.size();
    vector<int> cntA(c, 0);
    for (int i = 0; i < N; i++){
      int p = lower_bound(F.begin(), F.end(), gcd(K, A[i])) - F.begin();
      cntA[p]++;
    }
    vector<int> cntB(c, 0);
    for (int i = 0; i < M; i++){
      int p = lower_bound(F.begin(), F.end(), gcd(K, B[i])) - F.begin();
      cntB[p]++;
    }
    long long ans = 0;
    for (int i = 0; i < c; i++){
      for (int j = 0; j < c; j++){
        if ((long long) F[i] * F[j] % K == 0){
          ans += (long long) cntA[i] * cntB[j];
        }
      }
    }
    cout << ans << endl;
  }
}
0