結果
| 問題 |
No.798 コレクション
|
| コンテスト | |
| ユーザー |
azbrugby
|
| 提出日時 | 2019-03-16 00:16:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 1,712 bytes |
| コンパイル時間 | 767 ms |
| コンパイル使用メモリ | 83,944 KB |
| 実行使用メモリ | 35,072 KB |
| 最終ジャッジ日時 | 2024-07-01 22:10:06 |
| 合計ジャッジ時間 | 2,125 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#include <bitset>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1234567, N = 2010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;
ll mn(ll a, ll b) {
if (a == -1)return b;
if (b == -1)return a;
return min(a, b);
}
static ll gcd(ll v1, ll v2) {
if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}
ll pw(ll v1, ll v2) {
ll v3 = 1;
while (v2 > 0) {
if (v2 % 2)v3 = (v3*v1) % MOD;
v1 = (v1*v1) % MOD;
v2 /= 2;
}
return v3;
}
ll n,dp[N][N],n2;
pos g[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) { cin >> g[i].second >> g[i].first; g[i].first *= -1; }
sort(g + 1, g + n + 1);
n2 = n - (n / 3);
memset(dp, -1, sizeof(dp));
dp[1][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n2; j++) {
dp[i + 1][j] = mn(dp[i + 1][j], dp[i][j]);
if (j + 1 <= n2 && dp[i][j] != -1)dp[i + 1][j + 1] = mn(dp[i + 1][j + 1], dp[i][j] + g[i].second - g[i].first*j);
}
}
cout << dp[n + 1][n2] << endl;
return 0;
}
/*
static int x;
void InitA(int T, int X) { x = X; }
int GameA(int I, int J) {
gcd(1, 2);
if (I - 1 >= 1)return -1;
if (I + 1 <= 4)return -2;
if (J - 1 >= 1)return -3;
if (J + 1 <= 4)return -4;
}
void InitB(int T) { return; }
int GameB(int I, int J) {
gcd(1, 2);
return x;
if (I - 1 >= 1)return -1;
if (I + 1 <= 4)return -2;
if (J - 1 >= 1)return -3;
if (J + 1 <= 4)return -4;
}
*/
azbrugby