結果
| 問題 |
No.626 Randomized 01 Knapsack
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2017-12-16 20:47:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,166 bytes |
| コンパイル時間 | 914 ms |
| コンパイル使用メモリ | 92,152 KB |
| 実行使用メモリ | 17,912 KB |
| 最終ジャッジ日時 | 2024-12-15 22:15:09 |
| 合計ジャッジ時間 | 49,327 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 3 TLE * 15 |
ソースコード
#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 < 10000; 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