結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー StrorkisStrorkis
提出日時 2020-02-15 00:13:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 77,960 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2023-08-10 03:06:04
合計ジャッジ時間 2,725 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 55 ms
6,020 KB
testcase_11 AC 37 ms
4,376 KB
testcase_12 AC 143 ms
4,376 KB
testcase_13 AC 25 ms
4,380 KB
testcase_14 AC 53 ms
4,380 KB
testcase_15 AC 31 ms
4,376 KB
testcase_16 AC 70 ms
6,828 KB
testcase_17 AC 25 ms
4,376 KB
testcase_18 AC 146 ms
4,380 KB
testcase_19 AC 48 ms
4,376 KB
testcase_20 AC 241 ms
12,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int gcd(int a, int b) {
  int r = a % b;
  return r ? gcd(b, r) : b;
}

int main() {
  int n, m, k; cin >> n >> m >> k;
  char op; cin >> op;

  ll ans = 0;
  if (op == '+') {
    map<int, int> dict;
    for (int i = 0; i < m; i++) {
      int b; cin >> b;
      dict[b % k]++;
    }
    for (int i = 0; i < n; i++) {
      int a; cin >> a;
      ans += dict[(k - a % k) % k];
    }
  }
  else {
    map<int, int> dict1;
    map<int, int> dict2;
    for (int i = 0; i < m; i++) {
      int b; cin >> b;
      dict1[gcd(b, k)]++;
    }
    for (int i = 0; i < n; i++) {
      int a; cin >> a;
      dict2[gcd(a, k)]++;
    }
    for (P p1 : dict1) {
      for (P p2 : dict2) {
        if (1LL * p1.first * p2.first % k == 0) {
          ans += 1LL * p1.second * p2.second;
        }
      }
    }
  }
  cout << ans << endl;
}
0