結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー | kcvlex |
提出日時 | 2020-02-14 21:44:11 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,539 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 181,236 KB |
実行使用メモリ | 17,152 KB |
最終ジャッジ日時 | 2024-11-16 00:30:17 |
合計ジャッジ時間 | 4,558 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | RE | - |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 41 ms
7,552 KB |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | AC | 32 ms
6,820 KB |
testcase_15 | AC | 17 ms
6,820 KB |
testcase_16 | AC | 51 ms
8,832 KB |
testcase_17 | AC | 15 ms
6,816 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | AC | 172 ms
17,152 KB |
ソースコード
// #define DEBUGGING #include <bits/stdc++.h> #define endl '\n' #define ALL(V) (V).begin(), (V).end() #define ALLR(V) (V).rbegin(), (V).rend() using ll = std::int64_t; using ull = std::uint64_t; using PLL = std::pair<ll, ll>; using TLL = std::tuple<ll, ll, ll>; template <typename T> using V = std::vector<T>; template <typename T> using VV = V<V<T>>; template <typename T> const T& var_min(const T &t) { return t; } template <typename T> const T& var_max(const T &t) { return t; } template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); } template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); } template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); } template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); } template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); } template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); } namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; } #define mv_rec make_v(init, tail...) template <typename T> T make_v(T init) { return init; } template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); } #undef mv_rec using namespace std; #ifdef DEBUGGING #include "../../debug/debug.cpp" #else #define DEBUG(...) 0 #define DEBUG_SEPARATOR_LINE 0 #endif map<ll, ll> memo; V<ll> primes; ll dfs(ll cur, map<ll, ll> &cur_m, map<ll, ll> &max_m, map<ll, ll> &gcd_v) { { auto ite = memo.find(cur); if (ite != memo.end()) return ite->second; } ll ret = gcd_v[cur]; for (ll i = 0; i < primes.size(); i++) { ll p = primes[i]; ll c = cur_m[p]; ll m = max_m[p]; if (c < m) { cur_m[p]++; ret += dfs(cur * p, cur_m, max_m, gcd_v); cur_m[p]--; } } memo[cur] = ret; return ret; } ll solve_p(ll N, ll M, ll K, const V<ll> &A, const V<ll> &B) { map<ll, ll> cnt; for (ll e : A) cnt[e % K]++; ll ret = 0; for (ll e : B) { ll mod = e % K; ll key = (K - mod) % K; ret += cnt[key]; } return ret; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll solve_m(ll N, ll M, ll K, const V<ll> &A, const V<ll> &B) { map<ll, ll> gcd_v; for (ll e : B) gcd_v[gcd(e, K)]++; ll cpy = K; map<ll, ll> max_m; auto add_p = [&](ll key, ll val) { primes.push_back(key); max_m[key] += val; }; for (ll i = 2; i * i <= cpy; i++) { ll c = 0; while (cpy % i == 0) { cpy /= i; c++; } if (c) add_p(i, c); } if (1 < cpy) add_p(cpy, 1); map<ll, ll> cur_m; dfs(1, cur_m, max_m, gcd_v); ll ret = 0; for (ll e : A) { ll g = gcd(e, K); ret += memo[K / g]; } return ret; } int main() { ll N, M, K; cin >> N >> M >> K; char op; cin >> op; V<ll> B(M), A(N); for (ll &e : B) cin >> e; for (ll &e : A) cin >> e; assert(op == '+'); ll ans = (op == '+' ? solve_p(N, M, K, A, B) : solve_m(N, M, K, A, B)); cout << ans << endl; return 0; }