結果

問題 No.589 Counting Even
ユーザー furafura
提出日時 2020-06-10 12:10:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 3,277 ms
コンパイル使用メモリ 196,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 04:06:04
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

inline int popcount(long long x){
	x-=(x>>1)&0x5555555555555555LL;
	x=(x&0x3333333333333333LL)+((x>>2)&0x3333333333333333LL);
	x=(x+(x>>4))&0x0f0f0f0f0f0f0f0fLL;
	x=(x*0x0101010101010101LL)>>56;
	return x;
}

int s[61];
lint memo[62][2][2];

lint dfs(int i,bool smaller,bool ok){
	if(memo[i][smaller][ok]!=-1) return memo[i][smaller][ok];

	if(i==61) return memo[i][smaller][ok]=(ok?1:0);

	lint res=0;
	if(smaller){
		// i bit 目を 0 にする
		res+=dfs(i+1,true,ok);
		// i bit 目を 1 にする
		res+=dfs(i+1,true,ok||(s[i]==0));
	}
	else{
		// i bit 目を 0 にする
		res+=dfs(i+1,s[i]==1,ok);
		// i bit 目を 1 にする
		if(s[i]==1){
			res+=dfs(i+1,false,ok||(s[i]==0));
		}
	}
	return memo[i][smaller][ok]=res;
}

int main(){
	lint n; scanf("%lld",&n);

	rep(i,61) s[i]=n>>(60-i)&1;

	memset(memo,-1,sizeof memo);
	printf("%lld\n",dfs(0,false,false));

	return 0;
}
0