結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2021-01-11 00:39:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,420 bytes |
| コンパイル時間 | 642 ms |
| コンパイル使用メモリ | 92,544 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 01:26:26 |
| 合計ジャッジ時間 | 2,910 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 51 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d%d%d", &n, &m, &p);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 1330.cc: No.1330 Multiply or Divide - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 200000;
const int L = 31 * 31;
/* typedef */
typedef long long ll;
/* global variables */
int as[MAX_N], bs[MAX_N], cs[MAX_N], dp[L + 1];
/* subroutines */
/* main */
int main() {
int n, m, p;
scanf("%d%d%d", &n, &m, &p);
int maxa = 0;
for (int i = 0; i < n; i++) {
scanf("%d", as + i);
if (maxa < as[i]) maxa = as[i];
}
if (maxa > m) { puts("1"); return 0; }
int k = 0;
for (int i = 0; i < n; i++) {
int b = as[i], dc = 1;
while (b % p == 0) b /= p, dc++;
if (b > 1) {
bs[k] = b, cs[k] = dc;
k++;
}
}
if (k == 0) { puts("-1"); return 0; }
int ma = m / maxa;
memset(dp, -1, sizeof(dp));
dp[0] = 1;
for (int i = 0; i <= L; i++)
if (dp[i] >= 0) {
if ((ll)dp[i] > ma) {
printf("%d\n", i + 1);
return 0;
}
for (int j = 0; j < k; j++)
if (i + cs[j] <= L)
dp[i + cs[j]] =
min<ll>(max<ll>(dp[i + cs[j]], (ll)dp[i] * bs[j]), ma + 1);
}
puts("-1");
return 0;
}
tnakao0123