結果
問題 | No.798 コレクション |
ユーザー | 👑 jupiro |
提出日時 | 2020-02-02 06:02:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 30 ms / 2,000 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 1,278 ms |
コンパイル使用メモリ | 124,052 KB |
実行使用メモリ | 34,776 KB |
最終ジャッジ日時 | 2023-10-19 00:35:07 |
合計ジャッジ時間 | 3,122 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 2 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 2 ms
4,348 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 3 ms
4,348 KB |
testcase_09 | AC | 2 ms
4,348 KB |
testcase_10 | AC | 2 ms
4,348 KB |
testcase_11 | AC | 2 ms
4,348 KB |
testcase_12 | AC | 2 ms
4,348 KB |
testcase_13 | AC | 15 ms
17,088 KB |
testcase_14 | AC | 23 ms
25,536 KB |
testcase_15 | AC | 19 ms
22,368 KB |
testcase_16 | AC | 10 ms
12,072 KB |
testcase_17 | AC | 15 ms
17,616 KB |
testcase_18 | AC | 29 ms
32,928 KB |
testcase_19 | AC | 23 ms
26,856 KB |
testcase_20 | AC | 11 ms
12,336 KB |
testcase_21 | AC | 10 ms
11,280 KB |
testcase_22 | AC | 20 ms
22,368 KB |
testcase_23 | AC | 2 ms
4,348 KB |
testcase_24 | AC | 30 ms
34,776 KB |
testcase_25 | AC | 30 ms
34,776 KB |
ソースコード
#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> 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; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const 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) { return b > p.b; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N; scanf("%lld", &N); vector<Product> vp; vp.reserve(N); for (ll i = 0; i < N; i++) { ll a, b; scanf("%lld %lld", &a, &b); vp.emplace_back(a, b); } sort(vp.begin(), vp.end()); vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, INF)); dp[0][0] = 0; for (ll i = 0; i < N; i++) { for (ll j = 0; j <= N / 3; j++) { if (dp[i][j] == INF) continue; chmin(dp[i + 1][j], dp[i][j] + vp[i].a + vp[i].b * (i - j)); chmin(dp[i + 1][j + 1], dp[i][j]); } } cout << dp[N][N / 3] << endl; return 0; }