結果

問題 No.798 コレクション
ユーザー jupiro
提出日時 2020-04-29 03:44:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,612 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 134,116 KB
最終ジャッジ日時 2025-01-10 03:15:32
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:20: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |         ll n; scanf("%lld", &n);
      |               ~~~~~^~~~~~~~~~~~
main.cpp:61:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |                 ll a, b; scanf("%lld %lld", &a, &b);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Product {
	ll a, b;
	Product(ll _a, ll _b) :a(_a), b(_b) {}
	bool operator<(const Product& p) const {
		return b > p.b;
	}
};

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll n; scanf("%lld", &n);
	vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
	dp[0][0] = 0;
	vector<Product> vp; vp.reserve(n);
	for (int i = 0; i < n; i++) {
		ll a, b; scanf("%lld %lld", &a, &b);
		vp.emplace_back(a, b);
	}
	sort(vp.begin(), vp.end());
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= min<int>(n / 3, i); j++) {
			chmin(dp[i + 1][j + 1], dp[i][j]);
			chmin(dp[i + 1][j], dp[i][j] + vp[i].a + vp[i].b * (i - j));
		}
	}
	cout << dp[n][n / 3] << endl;
	return 0;
}


0