結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-04-10 22:47:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 88,828 KB
実行使用メモリ 13,208 KB
最終ジャッジ日時 2023-10-14 03:24:06
合計ジャッジ時間 3,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 53 ms
6,304 KB
testcase_11 AC 41 ms
4,356 KB
testcase_12 AC 116 ms
4,352 KB
testcase_13 AC 27 ms
4,352 KB
testcase_14 AC 55 ms
4,348 KB
testcase_15 AC 32 ms
4,348 KB
testcase_16 AC 65 ms
7,100 KB
testcase_17 AC 25 ms
4,348 KB
testcase_18 AC 117 ms
4,348 KB
testcase_19 AC 42 ms
4,352 KB
testcase_20 AC 174 ms
13,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  int in(N); int in(M); ll in(K);

  char in(op);
  vi A(N), B(M);
  rep(i, M) cin >> B[i];
  rep(i, N) cin >> A[i];

  if (op == '+') {
    map<int, int> count;
    ll ans = 0;
    rep(i, M) ++count[B[i] % K];
    rep(i, N) ans += count[(K - (A[i] % K)) % K];
    cout << ans << endl;
  } else {
    map<int, int> count, count2;
    rep(i, M) ++count[gcd(B[i], K)];
    rep(i, N) ++count2[gcd(A[i], K)];

    ll ans = 0;
    for (const auto& [a, e] : count2) {
      ll tmp = 0;
      for (int j = 1; j * j <= a; ++j) {
        if (a % j == 0) {
          tmp += count[K / (a/j)];
          if (a != j * j)
            tmp += count[K / j];
        }
      }
      ans += tmp * e;
    }
    cout << ans << endl;
  }

  return 0;
}
0