結果

問題 No.798 コレクション
ユーザー BwambocosBwambocos
提出日時 2019-03-16 12:28:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 807 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 178,580 KB
実行使用メモリ 34,644 KB
最終ジャッジ日時 2023-09-14 15:11:37
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 27 ms
16,632 KB
testcase_14 AC 44 ms
25,672 KB
testcase_15 AC 37 ms
22,076 KB
testcase_16 AC 16 ms
11,780 KB
testcase_17 AC 28 ms
17,168 KB
testcase_18 AC 60 ms
32,600 KB
testcase_19 AC 47 ms
26,904 KB
testcase_20 AC 17 ms
11,932 KB
testcase_21 AC 15 ms
10,884 KB
testcase_22 AC 37 ms
21,968 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 65 ms
34,644 KB
testcase_25 AC 64 ms
34,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 1123456789012345678;
LL N;
std::vector<std::pair<LL, LL>>item;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == N)
	{
		if (j == N - N / 3) return 0;
		return inf;
	}
	if (memo[i][j] != -1) return memo[i][j];
	LL res1 = dp(i + 1, j), res2 = dp(i + 1, j + 1) + item[i].second + item[i].first*j;
	return memo[i][j] = std::min(res1, res2);
}

int main()
{
	in >> N;
	std::vector<LL>A(N), B(N);
	rep(i, N) in >> A[i] >> B[i];

	rep(i, N) item.push_back(std::make_pair(B[i], A[i]));
	std::sort(item.begin(), item.end(), std::greater<std::pair<LL, LL>>());
	memo.resize(N);
	rep(i, memo.size()) memo[i].resize(N, -1);
	out << dp(0, 0) << std::endl;
}
0