結果

問題 No.54 Happy Hallowe'en
ユーザー snrnsidysnrnsidy
提出日時 2021-05-07 03:54:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 5,000 ms
コード長 1,468 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 136,224 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 19:26:31
合計ジャッジ時間 3,337 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 53 ms
4,356 KB
testcase_05 AC 79 ms
4,352 KB
testcase_06 AC 106 ms
4,352 KB
testcase_07 AC 138 ms
4,352 KB
testcase_08 AC 176 ms
4,352 KB
testcase_09 AC 214 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 213 ms
4,352 KB
testcase_13 AC 214 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <unordered_set>
#include <fstream>
#include <random>

using namespace std;

bool dp[2][20001];

bool cmp(pair<int, int> a, pair<int, int> b)
{
	if (a.second == b.second)
	{
		return a.first > b.first;
	}
	return a.second < b.second;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	vector <pair<int, int>> v;
	vector <pair<int, int>> p;

	int n, a, b;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		v.push_back(make_pair(a, b));
		p.push_back(make_pair(a + b, i));
	}


	int res = 0;
	sort(p.begin(), p.end());

	memset(dp, false, sizeof(dp));
	dp[1][0] = true;

	for (int I = 0; I < n; I++)
	{
		int i = p[I].second;
		memcpy(dp[0], dp[1], sizeof(dp[1]));
		memset(dp[1], false, sizeof(dp[1]));
		for (int j = 0; j < v[i].second; j++)
		{
			if (!dp[0][j])
			{
				continue;
			}
			dp[1][j + v[i].first] = true;
		}
		for (int j = 0; j <= 20000; j++)
		{
			if (dp[0][j])
			{
				dp[1][j] = true;
			}
		}
	}

	for (int i = 0; i <= 20000; i++)
	{
		if (dp[1][i])
		{
			res = max(res, i);
		}
	}

	cout << res << '\n';

	return 0;
}

0