結果

問題 No.798 コレクション
ユーザー どららどらら
提出日時 2019-03-16 01:40:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 1,660 ms
コンパイル使用メモリ 172,988 KB
実行使用メモリ 34,980 KB
最終ジャッジ日時 2023-09-14 14:57:47
合計ジャッジ時間 3,172 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
34,752 KB
testcase_01 AC 12 ms
34,756 KB
testcase_02 AC 12 ms
34,720 KB
testcase_03 AC 12 ms
34,756 KB
testcase_04 AC 12 ms
34,700 KB
testcase_05 AC 12 ms
34,892 KB
testcase_06 AC 12 ms
34,956 KB
testcase_07 AC 12 ms
34,784 KB
testcase_08 AC 12 ms
34,704 KB
testcase_09 AC 12 ms
34,772 KB
testcase_10 AC 12 ms
34,724 KB
testcase_11 AC 11 ms
34,748 KB
testcase_12 AC 12 ms
34,804 KB
testcase_13 AC 15 ms
34,836 KB
testcase_14 AC 15 ms
34,896 KB
testcase_15 AC 15 ms
34,808 KB
testcase_16 AC 14 ms
34,884 KB
testcase_17 AC 14 ms
34,840 KB
testcase_18 AC 17 ms
34,796 KB
testcase_19 AC 16 ms
34,832 KB
testcase_20 AC 14 ms
34,964 KB
testcase_21 AC 14 ms
34,800 KB
testcase_22 AC 16 ms
34,836 KB
testcase_23 AC 12 ms
34,744 KB
testcase_24 AC 17 ms
34,980 KB
testcase_25 AC 17 ms
34,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST {
  ll A, B;
  int i;
};
bool operator<(const ST& a, const ST& b){
  return a.B > b.B;
}

const ll INF = (ll)(1e15);
ll dp[2005][2005];

int main(){
  int N;
  cin >> N;

  int M = 0;
  {
    vector<int> tmp(N,0);
    int j = N-1;
    rep(d,N){
      if(tmp[d] == -1) break;
      M++;
      if(d%2 == 1){
        tmp[j] = -1;
        j--;
      }
    }
  }

  vector<ST> v;
  rep(i,N){
    ll a, b;
    cin >> a >> b;
    v.push_back((ST){a,b,i});
  }
  sort(ALLOF(v));

  rep(i,2005) rep(j,2005) dp[i][j] = INF;
  dp[0][0] = 0;
  rep(i,N){
    rep(j,i+1){
      if(dp[i][j] == INF) continue;
      if(i-j>=0) dp[i+1][j] = min(dp[i+1][j], dp[i][j] + v[i].A+v[i].B*(i-j));
      dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]);
    }
  }

  cout << dp[N][N-M] << endl;
  return 0;
}

0