結果
問題 | No.1330 Multiply or Divide |
ユーザー | 👑 jupiro |
提出日時 | 2021-01-23 03:05:43 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 2,429 bytes |
コンパイル時間 | 1,393 ms |
コンパイル使用メモリ | 143,612 KB |
実行使用メモリ | 17,116 KB |
最終ジャッジ日時 | 2023-08-28 13:10:21 |
合計ジャッジ時間 | 6,854 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 125 ms
17,100 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 20 ms
4,620 KB |
testcase_07 | AC | 94 ms
4,704 KB |
testcase_08 | AC | 210 ms
17,108 KB |
testcase_09 | AC | 232 ms
17,024 KB |
testcase_10 | AC | 208 ms
16,984 KB |
testcase_11 | AC | 196 ms
16,968 KB |
testcase_12 | AC | 216 ms
16,972 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 1 ms
4,380 KB |
testcase_16 | AC | 1 ms
4,376 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 199 ms
17,096 KB |
testcase_19 | AC | 190 ms
17,080 KB |
testcase_20 | AC | 183 ms
17,116 KB |
testcase_21 | AC | 178 ms
17,100 KB |
testcase_22 | AC | 186 ms
17,104 KB |
testcase_23 | AC | 30 ms
4,628 KB |
testcase_24 | AC | 2 ms
4,376 KB |
testcase_25 | AC | 2 ms
4,380 KB |
testcase_26 | AC | 2 ms
4,376 KB |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | AC | 2 ms
4,376 KB |
testcase_29 | AC | 1 ms
4,376 KB |
testcase_30 | AC | 2 ms
4,376 KB |
testcase_31 | AC | 2 ms
4,376 KB |
testcase_32 | AC | 2 ms
4,376 KB |
testcase_33 | AC | 1 ms
4,380 KB |
testcase_34 | AC | 118 ms
13,548 KB |
testcase_35 | AC | 26 ms
5,940 KB |
testcase_36 | AC | 100 ms
12,232 KB |
testcase_37 | AC | 89 ms
11,272 KB |
testcase_38 | AC | 51 ms
8,268 KB |
testcase_39 | AC | 34 ms
6,532 KB |
testcase_40 | AC | 41 ms
7,460 KB |
testcase_41 | AC | 20 ms
5,440 KB |
testcase_42 | AC | 79 ms
10,864 KB |
testcase_43 | AC | 99 ms
12,064 KB |
testcase_44 | AC | 21 ms
4,560 KB |
testcase_45 | AC | 21 ms
4,684 KB |
ソースコード
#include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> #include <cctype> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <utility> #include <fstream> using namespace std; typedef long long ll; using ull = unsigned long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } //template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); ll n, m, P; cin >> n >> m >> P; vector<ll> a(n); ll tm = 1; map<ll, ll> b; for (auto& e : a) { cin >> e; chmax(tm, e); ll cnt = 1; while (e % P == 0) e /= P, cnt += 1; if (e > 1) { if (b.count(e)) chmin(b[e], cnt); else b[e] = cnt; } } for (ll i = 1; i <= 62; i++) { ll mx = 0; for (auto [e, cnt] : b) { if (cnt == i) chmax(mx, e); } if (mx > 0) { for (auto itr = b.begin(); itr != b.end();) { if (itr->second == i and itr->first < mx) { itr = b.erase(itr); } else { itr++; } } } } if (tm > m) { cout << 1 << "\n"; return 0; } ll mx = *max_element(a.begin(), a.end()); if (mx == 1) { cout << -1 << "\n"; } else { map<ll, ll> mp; mp[1] = 0; ll res = INF; auto update = [&](ll x, ll y) { if (mp.count(x)) chmin(mp[x], y); else mp[x] = y; }; while (!mp.empty() and mp.begin()->first <= m) { if (mp.begin()->first * tm > m) { chmin(res, mp.begin()->second + 1); mp.erase(mp.begin()); } else { auto [t, cnt] = *mp.begin(); if (cnt >= res) continue; mp.erase(mp.begin()); for (auto [f, s] : b) { if (f == 1) continue; if(cnt + s < inf) update(t * f, cnt + s); } } } cout << res << "\n"; } }