提出 #67002716
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#ifdef DEBUG
const int debug = 1;
#else
const int debug = 0;
#endif
typedef long long int ll;
typedef pair<ll, ll> P;
using mint = atcoder::modint998244353;
const ll FOD = 998244353;
const ll INF = 1'000'000'000'000'000'009LL;
#define rep(I, N) for (ll I = 0; I < (ll)(N); I++)
ll n, k, m, q, h, w;
vector<ll> a, b, c;
ll mygcd (ll l, ll r) {
if (r == 0) return l;
return mygcd(r, l % r);
}
vector<mint> frac, invf;
void f_init (ll n) {
frac.resize(n+1);
invf.resize(n+1);
frac[0] = 1;
for (ll i = 1; i <= n; i++) {
frac[i] = frac[i-1] * i;
}
invf[n] = 1 / frac[n];
for (ll i = n; i >= 1; i--) {
invf[i-1] = invf[i] * i;
}
}
mint ncr (ll n, ll r) {
if (n < r || n < 0 || r < 0) return 0;
return frac[n] * invf[r] * invf[n-r];
}
mint put (ll ball, ll bucket) {
return ncr(ball + bucket - 1, ball);
}
const ll BITS = 61;
void solve () {
vector<vector<ll> > y(BITS);
rep (i, n) {
y[a[i]].push_back(+b[i]);
}
ll curr = w;
ll ans = 0;
rep (i, BITS) {
sort(y[i].begin(), y[i].end());
if (curr % 2) {
if (y[i].size() >= 1) {
ans += y[i][y[i].size()-1];
y[i].pop_back();
curr--;
}
}
if (i+1 < BITS) {
ll j = y[i].size()-1;
while (j >= 0) {
y[i+1].push_back(y[i][j] + ((j-1 >= 0) ? y[i][j-1] : 0));
j -= 2;
}
curr /= 2;
}
}
cout << ans << "\n";
return;
}
int main (void) {
if (!debug) {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
}
int T;
cin >> T;
while (T--) {
cin >> n >> w;
a.resize(n);
b.resize(n);
rep (i, n) {
cin >> a[i] >> b[i];
}
solve();
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Binary Knapsack |
| ユーザ | sheyasutaka |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 500 |
| コード長 | 1816 Byte |
| 結果 | AC |
| 実行時間 | 150 ms |
| メモリ | 10352 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample-01.txt |
| All | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, hand-01.txt, sample-01.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01-01.txt | AC | 150 ms | 3456 KiB |
| 01-02.txt | AC | 44 ms | 3472 KiB |
| 01-03.txt | AC | 31 ms | 3492 KiB |
| 01-04.txt | AC | 27 ms | 3596 KiB |
| 01-05.txt | AC | 30 ms | 4096 KiB |
| 01-06.txt | AC | 37 ms | 10236 KiB |
| 01-07.txt | AC | 35 ms | 10192 KiB |
| 01-08.txt | AC | 97 ms | 3480 KiB |
| 01-09.txt | AC | 38 ms | 3384 KiB |
| 01-10.txt | AC | 29 ms | 3528 KiB |
| 01-11.txt | AC | 29 ms | 4152 KiB |
| 01-12.txt | AC | 33 ms | 10324 KiB |
| 01-13.txt | AC | 33 ms | 10352 KiB |
| 01-14.txt | AC | 30 ms | 4136 KiB |
| 01-15.txt | AC | 34 ms | 10240 KiB |
| 01-16.txt | AC | 34 ms | 10156 KiB |
| 02-01.txt | AC | 30 ms | 3496 KiB |
| 02-02.txt | AC | 30 ms | 4100 KiB |
| 02-03.txt | AC | 37 ms | 10116 KiB |
| 02-04.txt | AC | 35 ms | 10196 KiB |
| 02-05.txt | AC | 23 ms | 4060 KiB |
| 02-06.txt | AC | 33 ms | 10236 KiB |
| 02-07.txt | AC | 22 ms | 10180 KiB |
| 02-08.txt | AC | 30 ms | 4068 KiB |
| 02-09.txt | AC | 36 ms | 10036 KiB |
| 02-10.txt | AC | 34 ms | 10124 KiB |
| 03-01.txt | AC | 23 ms | 9608 KiB |
| 03-02.txt | AC | 25 ms | 9560 KiB |
| 03-03.txt | AC | 24 ms | 9572 KiB |
| 03-04.txt | AC | 27 ms | 10236 KiB |
| 03-05.txt | AC | 34 ms | 10076 KiB |
| 03-06.txt | AC | 22 ms | 10168 KiB |
| 03-07.txt | AC | 37 ms | 9756 KiB |
| hand-01.txt | AC | 1 ms | 3500 KiB |
| sample-01.txt | AC | 1 ms | 3484 KiB |