結果
問題 | No.54 Happy Hallowe'en |
ユーザー | assy1028 |
提出日時 | 2015-03-25 14:35:25 |
言語 | C++11 (gcc 11.4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,418 bytes |
コンパイル時間 | 1,401 ms |
コンパイル使用メモリ | 154,648 KB |
実行使用メモリ | 394,948 KB |
最終ジャッジ日時 | 2023-09-11 10:08:42 |
合計ジャッジ時間 | 17,429 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 164 ms
394,292 KB |
testcase_01 | AC | 144 ms
394,232 KB |
testcase_02 | AC | 121 ms
394,292 KB |
testcase_03 | AC | 121 ms
394,476 KB |
testcase_04 | AC | 464 ms
394,424 KB |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | AC | 93 ms
394,432 KB |
testcase_11 | AC | 97 ms
394,228 KB |
testcase_12 | AC | 560 ms
394,884 KB |
testcase_13 | RE | - |
testcase_14 | AC | 94 ms
394,288 KB |
testcase_15 | AC | 93 ms
394,140 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
ソースコード
#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; int memo[10001][10001]; 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 { if (memo[sum][num] < 0) { int res = 0; if (t > sum) { res = calc(sum+v, num+1, n); } memo[sum][num] = max(res, calc(sum, num+1, n)); } return memo[sum][num]; } } 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)); memset(memo, -1, sizeof(memo)); 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)); }