結果
問題 | No.1330 Multiply or Divide |
ユーザー |
![]() |
提出日時 | 2021-01-09 17:02:03 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 1,328 bytes |
コンパイル時間 | 1,172 ms |
コンパイル使用メモリ | 127,336 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 01:25:01 |
合計ジャッジ時間 | 4,665 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <stack> #include <array> #include <list> #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair<int, int> P; int main() { int n; cin>>n; ll m, p; cin>>m>>p; ll a[200020]; for(int i=0; i<n; i++){ cin>>a[i]; } ll mx=*max_element(a, a+n); if(mx>m){ cout<<1<<endl; return 0; } ll x[30]; fill(x, x+30, 1); for(int i=0; i<n; i++){ int c=0; ll b=a[i]; while(b%p==0){ b/=p; c++; } x[c]=max(x[c], b); } ll dp[1024]={}; dp[0]=1; const ll MAX=1e9+7; for(int i=0; i<1024; i++){ for(int j=0; i+j+1<1024 && j<30; j++){ dp[i+j+1]=max(dp[i+j+1], min(dp[i]*x[j], MAX)); } } for(int i=0; i<1024; i++){ if(dp[i]>m/mx){ cout<<i+1<<endl; return 0; } } cout<<-1<<endl; return 0; }