結果
問題 | No.1330 Multiply or Divide |
ユーザー |
![]() |
提出日時 | 2020-10-30 16:37:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 764 bytes |
コンパイル時間 | 1,689 ms |
コンパイル使用メモリ | 197,284 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 00:54:42 |
合計ジャッジ時間 | 3,898 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
コンパイルメッセージ
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]); } | ~~~~~^~~~~~~~~~~~~
ソースコード
#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; }