結果
| 問題 | No.798 コレクション |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-03-21 16:30:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,315 bytes |
| 記録 | |
| コンパイル時間 | 780 ms |
| コンパイル使用メモリ | 87,624 KB |
| 実行使用メモリ | 14,260 KB |
| 最終ジャッジ日時 | 2024-09-19 01:44:56 |
| 合計ジャッジ時間 | 1,713 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
51 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:54:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
54 | scanf("%d%d", &bas[i].second, &bas[i].first);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 798.cc: No.798 コレクション - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 2000;
const int MAX_M = MAX_N / 3;
const long long LINF = 1LL << 62;
/* typedef */
typedef long long ll;
typedef pair<int,int> pii;
/* global variables */
pii bas[MAX_N];
ll dp[MAX_N + 1][MAX_M + 1];
/* subroutines */
inline void setmin(ll &a, ll b) { if (a > b) a = b; }
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &bas[i].second, &bas[i].first);
sort(bas, bas + n, greater<pii>());
int m = n / 3;
for (int i = 0; i <= n; i++)
fill(dp[i], dp[i] + m + 1, LINF);
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
int &ai = bas[i].second, &bi = bas[i].first;
for (int j = 0; j <= i && j <= m; j++)
if (dp[i][j] < LINF) {
if (j < m) setmin(dp[i + 1][j + 1], dp[i][j]);
setmin(dp[i + 1][j], dp[i][j] + ai + bi * (i - j));
}
}
printf("%lld\n", dp[n][m]);
return 0;
}
tnakao0123