結果
問題 | No.54 Happy Hallowe'en |
ユーザー | assy1028 |
提出日時 | 2015-03-25 14:42:50 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 3,137 ms / 5,000 ms |
コード長 | 1,448 bytes |
コンパイル時間 | 1,269 ms |
コンパイル使用メモリ | 167,560 KB |
実行使用メモリ | 395,216 KB |
最終ジャッジ日時 | 2024-04-23 16:40:46 |
合計ジャッジ時間 | 18,608 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 275 ms
394,340 KB |
testcase_01 | AC | 266 ms
394,288 KB |
testcase_02 | AC | 267 ms
394,320 KB |
testcase_03 | AC | 262 ms
394,352 KB |
testcase_04 | AC | 671 ms
394,536 KB |
testcase_05 | AC | 1,061 ms
394,752 KB |
testcase_06 | AC | 1,509 ms
394,928 KB |
testcase_07 | AC | 2,125 ms
394,940 KB |
testcase_08 | AC | 2,628 ms
395,204 KB |
testcase_09 | AC | 3,137 ms
395,112 KB |
testcase_10 | AC | 265 ms
394,316 KB |
testcase_11 | AC | 265 ms
394,272 KB |
testcase_12 | AC | 745 ms
395,168 KB |
testcase_13 | AC | 1,621 ms
395,216 KB |
testcase_14 | AC | 269 ms
394,136 KB |
testcase_15 | AC | 260 ms
394,332 KB |
testcase_16 | AC | 261 ms
394,340 KB |
testcase_17 | AC | 260 ms
394,336 KB |
testcase_18 | AC | 267 ms
394,332 KB |
コンパイルメッセージ
main.cpp: In function ‘int solve(int)’: main.cpp:49:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%d%d", &v, &t); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp: In function ‘int main()’: main.cpp:65:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 65 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#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 (sum > 10000) return sum; 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)); }