結果

問題 No.54 Happy Hallowe'en
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2016-06-11 17:09:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 842 bytes
コンパイル時間 2,562 ms
コンパイル使用メモリ 167,892 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-05 20:09:44
合計ジャッジ時間 3,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 42 ms
4,376 KB
testcase_05 AC 66 ms
4,376 KB
testcase_06 AC 90 ms
4,376 KB
testcase_07 AC 125 ms
4,380 KB
testcase_08 AC 157 ms
4,376 KB
testcase_09 AC 194 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 171 ms
4,376 KB
testcase_13 AC 191 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

int N;
pair<int, int> VT[10101];

bool dp[2][10101];

bool comp(pair<int, int> a, pair<int, int> b)
{
	return (a.second + a.first) < (b.first + b.second);
}

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

	while (cin >> N)
	{
		rep(i, 0, N)
		{
			int v, t; cin >> v >> t;
			VT[i] = make_pair(v, t);
		}

		sort(VT, VT + N, comp);
		
		rep(i, 0, 2) rep(j, 0, 10101) dp[i][j] = false;
		dp[0][0] = true;

		int ans = 0;
		rep(i, 0, N)
		{
			int ii = i + 1;

			rep(j, 0, 10101) dp[ii % 2][j] = false;
			rep(j, 0, 10101) if (dp[i % 2][j])
			{
				dp[ii % 2][j] = true;
				if (j < VT[i].second)
				{
					int jj = j + VT[i].first;
					ans = max(ans, jj);
					if(jj < 10000) dp[ii % 2][jj] = true;
				}
			}
		}

		cout << ans << endl;
	}
}
0