結果
問題 | No.626 Randomized 01 Knapsack |
ユーザー |
![]() |
提出日時 | 2017-12-16 20:45:01 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,165 bytes |
コンパイル時間 | 1,052 ms |
コンパイル使用メモリ | 92,000 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-15 22:13:52 |
合計ジャッジ時間 | 9,542 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 5 ms
6,816 KB |
testcase_03 | AC | 7 ms
6,816 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 265 ms
6,820 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 263 ms
6,816 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 4 ms
6,816 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; #define int long long int MOD = 1000000007; struct T { int v; int w; bool operator<(const T& right) const { return v * right.w > right.v * w; } }; struct State { int v; int w; //vector<int> goods; bool operator<(const State& right) const { return v * right.w < right.v * w; } }; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector<T> A(N); for (int i = 0; i < N; i++) { cin >> A[i].v >> A[i].w; } sort(A.begin(), A.end()); int w = 0; int v = 0; priority_queue<State> pq; priority_queue<State> npq; State st; st.v = 0; st.w = 0; pq.push(st); int res = -1; for (int i = 0; i < N; i++) { while ((int)npq.size() > 0)npq.pop(); for (int j = 0; j < 1000; j++) { if (pq.size() == 0) break; st = pq.top(); pq.pop(); npq.push(st); st.v += A[i].v; st.w += A[i].w; if (st.w <= W) { res = max(res, st.v); npq.push(st); } } swap(pq, npq); } cout << res << endl; }