結果
| 問題 |
No.626 Randomized 01 Knapsack
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2017-12-16 20:45:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 17 |
ソースコード
#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;
}
ats5515