結果

問題 No.798 コレクション
ユーザー ttttanttttan
提出日時 2019-03-16 19:15:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 801 bytes
コンパイル時間 1,403 ms
コンパイル使用メモリ 152,404 KB
実行使用メモリ 34,780 KB
最終ジャッジ日時 2023-09-14 15:26:15
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 8 ms
17,076 KB
testcase_14 AC 12 ms
25,580 KB
testcase_15 AC 11 ms
22,304 KB
testcase_16 AC 7 ms
12,108 KB
testcase_17 AC 9 ms
17,668 KB
testcase_18 AC 15 ms
32,796 KB
testcase_19 AC 12 ms
26,928 KB
testcase_20 AC 7 ms
12,464 KB
testcase_21 AC 6 ms
11,244 KB
testcase_22 AC 11 ms
22,328 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 15 ms
34,780 KB
testcase_25 AC 15 ms
34,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll inf=1000000000000000000;
int main(){
  ll n;cin>>n;
  ll a[n],b[n];
  vector<pll> v;
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    v.push_back(make_pair(b[i],a[i]));
  }
  sort(v.begin(),v.end(),greater<pll>());
  ll u;
  if(n%3==0)u=n/3*2;
  else if(n%3==1)u=(n-1)/3*2+1;
  else u=(n+1)/3*2;
  ll dp[n][n+1];
  for(ll i=0;i<n;i++)fill(dp[i],dp[i]+n+1,inf);
  dp[0][0]=0;
  dp[0][1]=v[0].first;
  for(ll i=1;i<n;i++){
    for(ll j=0;j<=i+1;j++){
      dp[i][j]=dp[i-1][j];
      if(j==0)continue;
      dp[i][j]=min(dp[i][j],dp[i-1][j-1]+v[i].second+v[i].first*(j-1));
    }
  }
  cout<<dp[n-1][u]<<endl;
  //for(ll i=0;i<n;i++){
    //for(ll j=0;j<=i+1;j++)cout<<dp[i][j]<<" ";
    //cout<<endl;
  //}
}
0