結果

問題 No.545 ママの大事な二人の子供
ユーザー y_taira_c
提出日時 2017-07-14 23:30:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 980 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 100,492 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-10-07 23:59:01
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 WA * 18 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

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