結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー 👑 emthrmemthrm
提出日時 2020-02-14 22:07:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,663 bytes
コンパイル時間 2,498 ms
コンパイル使用メモリ 220,248 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-27 19:42:00
合計ジャッジ時間 6,759 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
vector<pair<T, int> > prime_factorization(T val) {
  vector<pair<T, int> > res;
  for (T i = 2; i * i <= val; ++i) {
    if (val % i != 0) continue;
    int exponent = 0;
    while (val % i == 0) {
      ++exponent;
      val /= i;
    }
    res.emplace_back(i, exponent);
  }
  if (val != 1) res.emplace_back(val, 1);
  return res;
}

int main() {
  int n, m, k; char op; cin >> n >> m >> k >> op;
  vector<int> b(m); REP(i, m) cin >> b[i];
  vector<int> a(n); REP(i, n) cin >> a[i];
  ll ans = 0;
  if (op == '+') {
    map<int, int> mp;
    REP(i, m) ++mp[b[i] % k];
    REP(i, n) ans += mp[(k - a[i] % k) % k];
  } else if (op == '*') {
    if (k == 1) {
      cout << 1LL * n * m << '\n';
      return 0;
    }
    auto pri = prime_factorization(k);
    int sz = pri.size();
    const int N = 100000;
    vector<vector<bitset<N> > > cnt(sz);
    REP(i, sz) {
      int val, ex; tie(val, ex) = pri[i];
      cnt[i].resize(ex);
      REP(j, n) {
        int tmp = 0;
        while (tmp < ex && b[j] % val == 0) {
          ++tmp;
          b[j] /= val;
        }
        if (tmp > 0) cnt[i][tmp - 1].set(j);
      }
      for (int j = ex - 2; j >= 0; --j) cnt[i][j] |= cnt[i][j + 1];
    }
    bitset<N> base(0);
    REP(i, m) base.set(i);
    REP(i, n) {
      bitset<N> now = base;
      REP(j, sz) {
        int val, ex; tie(val, ex) = pri[j];
        int tmp = 0;
        while (tmp < ex && a[i] % val == 0) {
          ++tmp;
          a[i] /= val;
        }
        tmp = ex - tmp;
        if (tmp > 0) now &= cnt[j][tmp - 1];
      }
      ans += now.count();
    }
  }
  cout << ans << '\n';
  return 0;
}
0