結果
| 問題 | No.798 コレクション |
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2019-03-16 01:40:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,090 bytes |
| 記録 | |
| コンパイル時間 | 2,364 ms |
| コンパイル使用メモリ | 173,884 KB |
| 実行使用メモリ | 34,944 KB |
| 最終ジャッジ日時 | 2024-07-01 22:14:43 |
| 合計ジャッジ時間 | 4,097 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#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;
}
どらら