結果

問題 No.54 Happy Hallowe'en
ユーザー assy1028assy1028
提出日時 2015-03-25 14:32:49
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,410 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 162,184 KB
実行使用メモリ 328,600 KB
最終ジャッジ日時 2023-09-11 10:08:18
合計ジャッジ時間 8,416 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};

const int inf = 1000000009;
const double eps = 1e-8;

vector<T> vt;
unordered_map<P, int, pairhash> memo;

int calc(int sum, int num, int n) {
    int v = get<1>(vt[num]), t = get<2>(vt[num]);
    if (num == n-1) {
	return sum + (t > sum ? v : 0);
    } else {
	P p = make_pair(sum, num);
	if (memo.count(p) == 0) {
	    int res = 0;
	    if (t > sum) {
		res = calc(sum+v, num+1, n);
	    }
	    memo[p] = max(res, calc(sum, num+1, n));	    
	}
	return memo[p];
    }
}

int solve(int n) {
    for (int i = 0; i < n; i++) {
	int v, t;
	scanf("%d%d", &v, &t);
	vt.push_back(make_tuple(v+t, v, t));
    }
    sort(all(vt));
    return calc(0, 0, n);
}

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    */

    int n;
    scanf("%d", &n);
    printf("%d\n", solve(n));
}
0