結果

問題 No.1330 Multiply or Divide
ユーザー nok0
提出日時 2020-10-30 16:37:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 196,792 KB
最終ジャッジ日時 2025-01-15 16:32:19
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         scanf("%d %d %d", &n, &m, &p);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |         REP(i, n) { scanf("%d", &a[i]); }
      |                     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, x) for(int i = 0; i < (x); i++)
template <class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, m, p;
scanf("%d %d %d", &n, &m, &p);
vector a(n, 0), b(50, 0);
REP(i, n) { scanf("%d", &a[i]); }
int maxa = *max_element(a.begin(), a.end());
REP(i, n) {
int cnt = 1;
while(a[i] % p == 0) a[i] /= p, cnt++;
chmax(b[cnt], a[i]);
}
vector achive(3100, 1ll);
REP(i, 3000) {
REP(j, 50) {
if(achive[i] <= m) chmax(achive[i + j], achive[i] * b[j]);
}
}
REP(i, 3100) {
if(achive[i] * maxa > m) {
printf("%d\n", i + 1);
return 0;
}
}
puts("-1");
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0