結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー StrorkisStrorkis
提出日時 2020-02-14 23:57:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,029 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 77,360 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-04-27 20:38:54
合計ジャッジ時間 2,492 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 50 ms
6,944 KB
testcase_11 AC 37 ms
6,944 KB
testcase_12 WA -
testcase_13 AC 26 ms
6,940 KB
testcase_14 AC 53 ms
6,940 KB
testcase_15 AC 31 ms
6,944 KB
testcase_16 AC 62 ms
6,944 KB
testcase_17 AC 24 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 162 ms
12,800 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) {
      if (p1.first == k) {
        ans += 1LL * p1.second * n;
        continue;
      }
      for (P p2 : dict2) {
        if (p2.first == k || p1.first * p2.first % k == 0) {
          ans += 1LL * p1.second * p2.second;
        }
      }
    }
  }
  cout << ans << endl;
}
0