Problem:
Problem B: OOllOll
Problem
非負整数$x$を2進数表記したときの各桁の和を$f(x)$とする。
正整数$N$が与えられるので$f(0)$,$f(1)$,...,$f(N)$の中で最大のものを出力せよ。
関数$f(5)$の計算の例:
5を2進数表記すると101で各桁の和は1+0+1=2
よって$f(5) = 2$となる。
Note: https://ja.wikipedia.org/wiki/二進法
Input
入力は以下の形式で与えられる。
$N$
正整数$N$が1行に与えられる。
Constraints
入力は以下の条件を満たす。
$1 \le N \le 10^9$
Ouput
$f(0)$,$f(1)$,...,$f(N)$の中で最大のものを1行に出力する。
Sample Input 1
2
Sample Output 1
1
Sample Input 2
9
Sample Output 2
3

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
using namespace std;

class Time{
public:
  chrono::system_clock::time_point start;
  Time(){reset();}
  void reset(){start = now();}
  chrono::system_clock::time_point now(){return chrono::system_clock::now();}
  double time(){return chrono::duration_cast<chrono::milliseconds>(now()-start).count();}
};

signed main(){
  Time time;
  int n;
  cin>>n;
  n = min(n,1<<29);
  int ans = __builtin_popcount(n);
  if(n % 2 == 0) n--;
  while(n > 0 && time.time() < 990) ans = max(ans,(int)__builtin_popcount(n)),n-=2;
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.78125
time_ms: 980
memory_kb: 3084
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
using namespace std;

class Time{
public:
  chrono::system_clock::time_point start;
  Time(){reset();}
  void reset(){start = now();}
  chrono::system_clock::time_point now(){return chrono::system_clock::now();}
  double time(){return chrono::duration_cast<chrono::milliseconds>(now()-start).count();}
};

signed main(){
  Time time;
  int n;
  cin>>n;
  int ans = __builtin_popcount(n);
  if(n % 2 == 0) n--;
  while(n > 0 && time.time() < 990) ans = max(ans,(int)__builtin_popcount(n)),n-=2;
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.78125
time_ms: 980
memory_kb: 3084
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Time{
public:
  chrono::system_clock::time_point start;
  Time(){reset();}
  void reset(){start = now();}
  chrono::system_clock::time_point now(){return chrono::system_clock::now();}
  double time(){return chrono::duration_cast<chrono::milliseconds>(now()-start).count();}
};

signed main(){
  Time time;
  int n;
  cin>>n;
  int ans = __builtin_popcount(n);
  if(n % 2 == 0) n--;
  while(n > 0 && time.time() < 980) Max(ans,(int)__builtin_popcount(n)),n-=2;
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.78125
time_ms: 970
memory_kb: 3084
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Time{
public:
  chrono::system_clock::time_point start;
  Time(){reset();}
  void reset(){start = now();}
  chrono::system_clock::time_point now(){return chrono::system_clock::now();}
  double time(){return chrono::duration_cast<chrono::milliseconds>(now()-start).count();}
};

signed main(){
  Time time;
  int n;
  cin>>n;
  int ans = __builtin_popcount(n);
  if(n % 2 == 0) n--;
  while(n > 0 && time.time() < 980) Max(ans,(int)__builtin_popcount(n--));
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.09375
time_ms: 970
memory_kb: 3068
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class Time{
public:
  chrono::system_clock::time_point start;
  Time(){reset();}
  void reset(){start = now();}
  chrono::system_clock::time_point now(){return chrono::system_clock::now();}
  double time(){return chrono::duration_cast<chrono::milliseconds>(now()-start).count();}
};

signed main(){
  Time time;
  int n;
  cin>>n;
  int ans = 0;
  while(n > 0 && time.time() < 950) Max(ans,(int)__builtin_popcount(n--));
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.09375
time_ms: 940
memory_kb: 3056
final_rank: 4