結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー StrorkisStrorkis
提出日時 2020-02-14 23:12:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,428 bytes
コンパイル時間 886 ms
コンパイル使用メモリ 89,468 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-27 20:12:17
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;

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 == '+') {
    vector<int> v(m);
    for (int i = 0; i < m; i++) {
      int b; cin >> b;
      v[i] = b % k;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
      int a; cin >> a;
      int x = (k - a % k) % k;
      int l = 0, r = m;
      while (l < r) {
        int c = (l + r) / 2;
        if (v[c] < x)
          l = c + 1;
        else
          r = c;
      }
      if (v[l] != x) continue;
      int tmp = l;
      r = m;
      while (l < r) {
        int c = (l + r) / 2;
        if (v[c] <= x)
          l = c + 1;
        else
          r = c;
      }
      ans += l - tmp;
    }
  }
  else {
    int d = 1;
    while (d * d <= k) d++;
    map<int, int> dic;
    int count = 0;
    for (int i = 0; i < m; i++) {
      int b; cin >> b;
      if (b % k == 0) {
        count++;
        continue;
      }
      int x = gcd(b, k);
      for (int j = 2; j < d; j++) {
        if (x % j == 0) dic[j]++;
      }
    }
    for (int i = 0; i < n; i++) {
      int a; cin >> a;
      if (a % k == 0) {
        ans += m;
        continue;
      }
      ans += dic[k / gcd(a, k)] + count;
    }
  }
  cout << ans << endl;
}
0