結果
| 問題 | No.3670 Fast Knapsack |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-09-06 12:24:37 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
RE
不安定
|
| 実行時間 | - |
| コード長 | 1,431 bytes |
| 記録 | |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 68,096 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-06 12:25:46 |
| 合計ジャッジ時間 | 8,987 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 RE * 6 TLE * 1 -- * 13 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 3670.cc: No.3670 Fast Knapsack - yukicoder
*/
#include<cstdio>
#include<cstdint>
#include<vector>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_S = 200000;
/* typedef */
struct Mybitset {
using ull = uint64_t;
int l;
vector<ull> bs;
Mybitset(int _s): l((_s + 64 - 1) / 64), bs(l + 1, 0) {}
void print() const {
for (int i = l - 1; i >= 0; i--)
for (int j = 63; j >= 0; j--) putchar('0' + ((bs[i] >> j) & 1));
putchar('\n');
}
void set(int x) { bs[x / 64] |= (1ULL << (x & 63)); }
Mybitset &shitor(int x) {
int xq = x / 64, xr = x & 63;
for (int i = l - xq; i >= 0; i--) {
ull b0 = (bs[i] << xr), b1 = (bs[i] >> (64 - xr));
bs[i + xq] |= b0, bs[i + xq + 1] |= b1;
}
//print();
return *this;
}
int msb(int s) const {
int q = s / 64, r = s & 63;
while (s >= 0) {
if ((bs[q] >> r) & 1) return s;
if (--r < 0) r = 63, q--;
s--;
}
return -1;
}
};
/* global variables */
int as[MAX_N];
/* subroutines */
/* main */
int main() {
int tn;
scanf("%d", &tn);
while (tn--) {
int n, s;
scanf("%d%d", &n, &s);
for (int i = 0; i < n; i++) scanf("%d", as + i);
Mybitset dp(s + 1);
dp.set(0);
for (int i = 0; i < n; i++) dp.shitor(as[i]);
int maxs = dp.msb(s);
printf("%d\n", maxs);
}
return 0;
}
tnakao0123