結果

問題 No.1463 Hungry Kanten
ユーザー tkmst201tkmst201
提出日時 2021-05-09 21:10:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,683 ms / 2,000 ms
コード長 2,364 bytes
コンパイル時間 3,150 ms
コンパイル使用メモリ 219,504 KB
実行使用メモリ 76,244 KB
最終ジャッジ日時 2023-10-19 05:43:03
合計ジャッジ時間 8,823 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 45 ms
6,168 KB
testcase_03 AC 671 ms
52,896 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 1,683 ms
76,244 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 4 ms
4,348 KB
testcase_14 AC 12 ms
4,552 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 47 ms
6,292 KB
testcase_17 AC 147 ms
11,584 KB
testcase_18 AC 133 ms
5,644 KB
testcase_19 AC 747 ms
35,760 KB
testcase_20 AC 1,162 ms
44,260 KB
testcase_21 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

std::vector<std::pair<int, int>> prime_factorization(ll n) {
	std::vector<std::pair<int, int>> res;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) res.emplace_back(i, 1), n /= i;
		while (n % i == 0) ++res.back().second, n /= i;
	}
	if (n > 1) res.emplace_back(n, 1);
	return res;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	vector<vector<pii>> vec(N);
	REP(i, N) {
		scanf("%d", &A[i]);
		vec[i] = prime_factorization(A[i]);
	}
	struct Vec {
		vector<pii> val;
		Vec (const vector<pii> & v) : val(v) {}
		int size() const noexcept { return val.size(); }
		pii & operator[](int k) { return val[k]; }
		pii operator[](int k) const { return val[k]; }
		bool operator <(const Vec & rhs) const {
			if (size() != rhs.size()) return size() < rhs.size();
			REP(i, size()) if (val[i] != rhs[i]) return val[i] < rhs[i];
			return true;
		}
	};
	set<Vec> ss;
	REP(i, 1 << N) {
		auto func = [&](auto v1, auto v2) {
			vector<pii> res;
			int p1 = 0, p2 = 0;
			while (p1 < v1.size() || p2 < v2.size()) {
				if (p1 < v1.size() && p2 < v2.size()) {
					if (v1[p1].first == v2[p2].first) {
						res.emplace_back(v1[p1].first, v1[p1].second + v2[p2].second);
						++p1; ++p2;
					}
					else if (v1[p1].first < v2[p2].first) res.emplace_back(v1[p1++]);
					else res.emplace_back(v2[p2++]);
				}
				else if (p1 < v1.size()) res.emplace_back(v1[p1++]);
				else res.emplace_back(v2[p2++]);
			}
			return res;
		};
		
		int p = 0, sum = 0;
		vector<pii> v;
		REP(j, N) if (i >> j & 1) {
			++p;
			sum += A[j];
			v = func(v, vec[j]);
		}
		if (p < K) continue;
		ss.insert(prime_factorization(sum));
		ss.insert(v);
	}
	int ans = 0;
	vector<pii> prv;
	for (auto v : ss) {
		ans += prv != v.val;
		prv = v.val;
	}
	cout << ans << endl;
}
0