結果

問題 No.798 コレクション
ユーザー azbrugbyazbrugby
提出日時 2019-03-16 00:16:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 78,584 KB
実行使用メモリ 35,076 KB
最終ジャッジ日時 2023-09-14 14:52:19
合計ジャッジ時間 2,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
34,796 KB
testcase_01 AC 11 ms
35,028 KB
testcase_02 AC 11 ms
34,964 KB
testcase_03 AC 11 ms
34,776 KB
testcase_04 AC 11 ms
34,788 KB
testcase_05 AC 11 ms
34,888 KB
testcase_06 AC 11 ms
34,844 KB
testcase_07 AC 11 ms
34,820 KB
testcase_08 AC 11 ms
34,776 KB
testcase_09 AC 11 ms
34,908 KB
testcase_10 AC 11 ms
34,788 KB
testcase_11 AC 11 ms
35,076 KB
testcase_12 AC 11 ms
34,900 KB
testcase_13 AC 14 ms
34,940 KB
testcase_14 AC 16 ms
34,920 KB
testcase_15 AC 15 ms
34,868 KB
testcase_16 AC 14 ms
34,840 KB
testcase_17 AC 14 ms
34,840 KB
testcase_18 AC 18 ms
34,896 KB
testcase_19 AC 16 ms
34,864 KB
testcase_20 AC 13 ms
34,808 KB
testcase_21 AC 13 ms
34,836 KB
testcase_22 AC 15 ms
34,928 KB
testcase_23 AC 12 ms
34,792 KB
testcase_24 AC 17 ms
34,872 KB
testcase_25 AC 18 ms
34,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
*/
0