結果

問題 No.911 ラッキーソート
ユーザー furafura
提出日時 2020-07-24 21:34:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 3,608 ms
コンパイル使用メモリ 200,688 KB
実行使用メモリ 4,896 KB
最終ジャッジ日時 2023-09-08 03:33:45
合計ジャッジ時間 7,490 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 134 ms
4,896 KB
testcase_14 AC 136 ms
4,580 KB
testcase_15 AC 134 ms
4,612 KB
testcase_16 AC 139 ms
4,672 KB
testcase_17 AC 138 ms
4,664 KB
testcase_18 AC 139 ms
4,608 KB
testcase_19 AC 136 ms
4,844 KB
testcase_20 AC 134 ms
4,536 KB
testcase_21 AC 136 ms
4,532 KB
testcase_22 AC 133 ms
4,668 KB
testcase_23 AC 123 ms
4,572 KB
testcase_24 AC 114 ms
4,376 KB
testcase_25 AC 72 ms
4,380 KB
testcase_26 AC 54 ms
4,376 KB
testcase_27 AC 27 ms
4,380 KB
testcase_28 AC 14 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 139 ms
4,620 KB
testcase_39 AC 130 ms
4,440 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 136 ms
4,588 KB
testcase_42 AC 85 ms
4,380 KB
testcase_43 AC 135 ms
4,740 KB
testcase_44 AC 129 ms
4,672 KB
testcase_45 AC 133 ms
4,544 KB
testcase_46 AC 131 ms
4,848 KB
testcase_47 AC 129 ms
4,568 KB
testcase_48 AC 126 ms
4,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

int bit[63];
lint memo[63][2];

lint dfs(int b,lint k,bool smaller){
	if(b==-1) return 1;

	if(memo[b][smaller]!=-1) return memo[b][smaller];

	lint res=0;
	// 2^b の桁を 0 にする
	if(bit[b]!=1){
		res+=dfs(b-1,k,smaller||(k>>b&1)==1);
	}
	// 2^b の桁を 1 にする
	if(bit[b]!=0 && (smaller||(k>>b&1)==1)){
		res+=dfs(b-1,k,smaller);
	}
	return memo[b][smaller]=res;
}

int main(){
	int n;
	lint l,r; cin>>n>>l>>r;
	vector<lint> a(n);
	rep(i,n) cin>>a[i];

	rep(b,63) bit[b]=-1;
	rep(i,n-1){
		int b;
		for(b=62;b>=0;b--) if((a[i]^a[i+1])>>b&1) break;
		if(a[i]<a[i+1]){
			if(bit[b]==1) return puts("0"),0;
			bit[b]=0;
		}
		else{
			if(bit[b]==0) return puts("0"),0;
			bit[b]=1;
		}
	}

	memset(memo,-1,sizeof memo);
	lint ans=dfs(62,r,false);
	if(l>0){
		memset(memo,-1,sizeof memo);
		ans-=dfs(62,l-1,false);
	}
	cout<<ans<<'\n';

	return 0;
}
0