Submission #67002415
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define endl "\n"
typedef pair<int, int> Pii;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(x) begin(x), end(x)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(s) (s).begin(),(s).end()
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define FOR_(n) for (ll _ = 0; (_) < (ll)(n); ++(_))
#define FOR(i, n) for (ll i = 0; (i) < (ll)(n); ++(i))
#define se second
#define pb push_back
#define P pair<ll,ll>
#define PQminll priority_queue<ll, vector<ll>, greater<ll>>
#define PQmaxll priority_queue<ll,vector<ll>,less<ll>>
#define PQminP priority_queue<P, vector<P>, greater<P>>
#define PQmaxP priority_queue<P,vector<P>,less<P>>
#define NP next_permutation
#define die(a) {cout<<a<<endl;return 0;}
#define dier(a) {return a;}
//const ll mod = 1000000009;
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 4000000000000000000ll;
const ld eps = ld(0.00000000001);
static const long double pi = 3.141592653589793;
template<class T>void vcin(vector<T> &n){for(int i=0;i<int(n.size());i++) cin>>n[i];}
template<class T,class K>void vcin(vector<T> &n,vector<K> &m){for(int i=0;i<int(n.size());i++) cin>>n[i]>>m[i];}
template<class T>void vcout(vector<T> &n){for(int i=0;i<int(n.size());i++){cout<<n[i]<<" ";}cout<<endl;}
template<class T>void vcin(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cin>>n[i][j];}}}
template<class T>void vcout(vector<vector<T>> &n){for(int i=0;i<int(n.size());i++){for(int j=0;j<int(n[i].size());j++){cout<<n[i][j]<<" ";}cout<<endl;}cout<<endl;}
void yes(bool a){cout<<(a?"yes":"no")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void possible(bool a){ cout<<(a?"possible":"impossible")<<endl; }
void Possible(bool a){ cout<<(a?"Possible":"Impossible")<<endl; }
void POSSIBLE(bool a){ cout<<(a?"POSSIBLE":"IMPOSSIBLE")<<endl; }
#define FOR_R(i, n) for (ll i = (ll)(n)-1; (i) >= 0; --(i))
template<class T>auto min(const T& a){ return *min_element(all(a)); }
//template<class T>auto max(const T& a){ return *max_element(all(a)); }
template<class T,class F>void print(pair<T,F> a){cout<<a.fi<<" "<<a.se<<endl;}
template<class T>bool chmax(T &a,const T b) { if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a,const T b) { if (b<a) { a=b; return 1; } return 0;}
template<class T> void ifmin(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
template<class T> void ifmax(T t,T u){if(t>u){cout<<-1<<endl;}else{cout<<t<<endl;}}
ll fastgcd(ll u,ll v){ll shl=0;while(u&&v&&u!=v){bool eu=!(u&1);bool ev=!(v&1);if(eu&&ev){++shl;u>>=1;v>>=1;}else if(eu&&!ev){u>>=1;}else if(!eu&&ev){v>>=1;}else if(u>=v){u=(u-v)>>1;}else{ll tmp=u;u=(v-u)>>1;v=tmp;}}return !u?v<<shl:u<<shl;}
ll modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
vector<ll> divisor(ll x){ vector<ll> ans; for(ll i = 1; i * i <= x; i++){ if(x % i == 0) {ans.push_back(i); if(i*i!=x){ ans.push_back(x / ans[i]);}}}sor(ans); return ans; }
ll pop(ll x){return __builtin_popcountll(x);}
ll poplong(ll x){ll y=-1;while(x){x/=2;y++;}return y;}
P hyou(P a){ll x=fastgcd(abs(a.fi),abs(a.se));a.fi/=x;a.se/=x;if(a.se<0){a.fi*=-1;a.se*=-1;}return a;}
P Pplus(P a,P b){ return hyou({a.fi*b.se+b.fi*a.se,a.se*b.se});}
P Ptimes(P a,ll b){ return hyou({a.fi*b,a.se});}
P Ptimes(P a,P b){ return hyou({a.fi*b.fi,a.se*b.se});}
P Pminus(P a,P b){ return hyou({a.fi*b.se-b.fi*a.se,a.se*b.se});}
P Pgyaku(P a){ return hyou({a.se,a.fi});}
void cincout(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(15);
}
int main() {
cincout();
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
ll w;
cin>>w;
vector<vector<ll>> d(60);
for(int i=0;i<n;i++){
ll x,y;
cin>>x>>y;
d[x].pb(y);
}
vector<ll> dp(n+1);
if(w+1<=n+1) dp.resize(w+1);
for(int i=0;i<60;i++){
sor(d[i]);
rever(d[i]);
vector<ll> dp2(min(n,w/(1ll<<i))+1);
dp2[0]=dp[0];
ll x=0,y=0;
for(int j=1;j<dp2.size();j++){
if(y==d[i].size()){
dp2[j]=dp2[j-1]+(dp[x+1]-dp[x]);
x++;
}
else if(x+1==dp.size()){
dp2[j]=dp2[j-1]+d[i][y];
y++;
}
else if(dp[x+1]-dp[x]<d[i][y]){
dp2[j]=dp2[j-1]+d[i][y];
y++;
}
else{
dp2[j]=dp2[j-1]+(dp[x+1]-dp[x]);
x++;
}
}
/* for(auto e:dp) cerr<<e<<" ";
cerr<<endl;
for(auto e:dp2) cerr<<e<<" ";
cerr<<endl;*/
dp=dp2;
vector<ll> dp3(min(n+1,w/(1ll<<(i+1))+1));
for(int j=0;j<dp.size();j++){
chmax(dp3[w/(1ll<<(i+1))-(w/(1ll<<i)-j)/2],dp[j]);
}
dp=dp3;
// for(auto e:dp) cerr<<e<<" ";
// cerr<<endl;
// cerr<<endl;
}
cout<<dp[0]<<endl;
}
}
Submission Info
Submission Time
2025-06-22 21:13:14+0900
Task
B - Binary Knapsack
User
PCTprobability
Language
C++ 20 (gcc 12.2)
Score
500
Code Size
5568 Byte
Status
AC
Exec Time
304 ms
Memory
10176 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:102:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
102 | for(int j=1;j<dp2.size();j++){
| ~^~~~~~~~~~~
Main.cpp:103:13: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
103 | if(y==d[i].size()){
| ~^~~~~~~~~~~~~
Main.cpp:107:20: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
107 | else if(x+1==dp.size()){
| ~~~^~~~~~~~~~~
Main.cpp:126:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
126 | for(int j=0;j<dp.size();j++){
| ~^~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
500 / 500
Status
Set Name
Test Cases
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
Case Name
Status
Exec Time
Memory
01-01.txt
AC
304 ms
3520 KiB
01-02.txt
AC
96 ms
3388 KiB
01-03.txt
AC
68 ms
3636 KiB
01-04.txt
AC
59 ms
3672 KiB
01-05.txt
AC
82 ms
3968 KiB
01-06.txt
AC
100 ms
9944 KiB
01-07.txt
AC
100 ms
9812 KiB
01-08.txt
AC
182 ms
3576 KiB
01-09.txt
AC
69 ms
3468 KiB
01-10.txt
AC
53 ms
3596 KiB
01-11.txt
AC
75 ms
4076 KiB
01-12.txt
AC
96 ms
10044 KiB
01-13.txt
AC
77 ms
9988 KiB
01-14.txt
AC
82 ms
4024 KiB
01-15.txt
AC
101 ms
9920 KiB
01-16.txt
AC
102 ms
9900 KiB
02-01.txt
AC
65 ms
3632 KiB
02-02.txt
AC
83 ms
3928 KiB
02-03.txt
AC
103 ms
9992 KiB
02-04.txt
AC
101 ms
9828 KiB
02-05.txt
AC
76 ms
4120 KiB
02-06.txt
AC
101 ms
9688 KiB
02-07.txt
AC
90 ms
9872 KiB
02-08.txt
AC
82 ms
3960 KiB
02-09.txt
AC
101 ms
9892 KiB
02-10.txt
AC
100 ms
9788 KiB
03-01.txt
AC
92 ms
9424 KiB
03-02.txt
AC
92 ms
9348 KiB
03-03.txt
AC
22 ms
8040 KiB
03-04.txt
AC
96 ms
10176 KiB
03-05.txt
AC
101 ms
9820 KiB
03-06.txt
AC
92 ms
9944 KiB
03-07.txt
AC
102 ms
9968 KiB
hand-01.txt
AC
1 ms
3532 KiB
sample-01.txt
AC
1 ms
3572 KiB