結果

問題 No.798 コレクション
ユーザー goodbatongoodbaton
提出日時 2019-03-16 19:04:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,583 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 101,200 KB
実行使用メモリ 34,800 KB
最終ジャッジ日時 2023-09-14 15:26:08
合計ジャッジ時間 2,251 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 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 10 ms
25,704 KB
testcase_14 AC 14 ms
29,980 KB
testcase_15 AC 13 ms
28,068 KB
testcase_16 AC 8 ms
21,400 KB
testcase_17 AC 11 ms
25,732 KB
testcase_18 AC 17 ms
34,132 KB
testcase_19 AC 14 ms
32,076 KB
testcase_20 AC 9 ms
21,416 KB
testcase_21 AC 8 ms
19,356 KB
testcase_22 AC 12 ms
27,952 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 16 ms
34,784 KB
testcase_25 AC 17 ms
34,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2010

ll dp[SIZE][SIZE];

int main(){
  int n;
  pair<int,int> p[SIZE];

  cin >> n;

  for(int i=0;i<n;i++){
    int a, b;
    cin >> a >> b;
    p[i] = {b, a};
  }

  sort(p, p+n);
  reverse(p, p+n);

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      dp[i][j] = LLINF;

  dp[0][0] = 0;

  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
      dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p[i].second + p[i].first * j);
    }
  }

  int d = 0, sum = 0;

  while (sum < n) {
    sum += 1 + d%2;
    d++;
  }

  cout << dp[n][d] << endl;

  return 0;
}
0