結果

問題 No.1330 Multiply or Divide
ユーザー nok0
提出日時 2020-10-30 17:17:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,077 bytes
コンパイル時間 2,280 ms
コンパイル使用メモリ 196,644 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 00:54:42
合計ジャッジ時間 4,290 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%d %d %d", &n, &m, &p);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:33:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |                 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;
}
bool is_Prime(long long n) {
	if(n <= 1) return false;
	for(int i = 2; i <= sqrt(n); i++)
		if(n % i == 0) return false;
	return true;
}


int main() {
	int n, m, p;
	scanf("%d %d %d", &n, &m, &p);
	assert(1<=n and n <= 200000);
	assert(1 <= m and m <= 1000000000);
	assert(1 <= p and p <= 1000000000);
	assert(is_Prime(p));

	vector a(n, 0), b(50, 0);
	REP(i, n) { 
		scanf("%d", &a[i]);
		assert(1 <= a[i] and a[i] <= 1000000000);
	}

	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;
}
0