結果

問題 No.545 ママの大事な二人の子供
ユーザー y_taira_cy_taira_c
提出日時 2017-07-14 23:30:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 99,980 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-16 20:44:15
合計ジャッジ時間 4,811 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,320 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <chrono>
#include <unordered_map>



using namespace std;

typedef long long int ll;

#define REP(i,n) for(int i=0; i<(n); ++i )
#define REPR(i,n) for(int i=(n); i>=0; --i)
#define FOR(i,a,n) for(int i=(a); i<(n); ++i )
#define FORR(i,a,n) for(int i=(n); i>=(a); --i)

#define DOUT(x) cerr << #x << " = " << (x) << "\n";
#define COUT(x) cout << (x) << "\n";



vector<pair<int, int>> a;
vector<int> b;
int n;
int f(int i, int sa)
{
	if (i == n)return 0;
	if (b[i] != 0)return b[i];
	int x = f(i + 1, sa - a[i].second) - a[i].second;;
	int y = f(i + 1, sa + a[i].first)+a[i].first;
	if (abs(x) < abs(y)) return b[i] = x;
	return b[i] = y;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	a.resize(n);
	b.resize(n, 0);
	REP(i, n)
	{
		cin >> a[i].first >> a[i].second;
	}
	COUT(f(0, 0));
	return 0;
}
0