結果

問題 No.911 ラッキーソート
ユーザー leaf_1415leaf_1415
提出日時 2019-10-18 22:20:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 872 ms
コンパイル使用メモリ 60,436 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-09-07 23:57:14
合計ジャッジ時間 5,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 91 ms
4,976 KB
testcase_14 AC 92 ms
4,900 KB
testcase_15 AC 89 ms
4,972 KB
testcase_16 AC 90 ms
4,924 KB
testcase_17 AC 93 ms
5,120 KB
testcase_18 AC 90 ms
4,920 KB
testcase_19 AC 92 ms
4,912 KB
testcase_20 AC 87 ms
4,968 KB
testcase_21 AC 86 ms
4,964 KB
testcase_22 AC 80 ms
4,924 KB
testcase_23 AC 74 ms
4,756 KB
testcase_24 AC 68 ms
4,680 KB
testcase_25 AC 41 ms
4,380 KB
testcase_26 AC 32 ms
4,380 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 90 ms
4,984 KB
testcase_39 AC 76 ms
4,792 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 87 ms
4,908 KB
testcase_42 AC 51 ms
4,460 KB
testcase_43 AC 86 ms
4,976 KB
testcase_44 AC 39 ms
4,984 KB
testcase_45 AC 40 ms
4,968 KB
testcase_46 AC 40 ms
4,924 KB
testcase_47 AC 43 ms
4,972 KB
testcase_48 AC 38 ms
4,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

llint n, l, r;
llint a[200005];
bool up[65], down[35];
llint dp[65][2];

bool dfs(llint l, llint r, llint h)
{
	int bd = 0;
	for(int i = l; i < r; i++){
		if(((a[i] >> h) & 1) < ((a[i+1] >> h) & 1)) up[h] = true, bd = i;
		if(((a[i] >> h) & 1) > ((a[i+1] >> h) & 1)) down[h] = true, bd = i;
	}
	if(up[h] && down[h]) return false;
	if(h > 0){
		if(bd) dfs(l, bd, h-1), dfs(bd+1, r, h-1);
		else dfs(l, r, h-1);
	}
	return true;
}

llint calc(llint x)
{
	if(x < 0) return 0;
	for(int i = 61; i >= 0; i--){
		for(int j = 0; j < 2; j++){
			dp[i][j] = 0;
		}
	}
	dp[61][0] = 1;
	
	for(int i = 61; i > 0; i--){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < 2; k++){
				if(up[i-1] && k == 1) continue;
				if(down[i-1] && k == 0) continue;
				if(k == 1 && ((x&(1LL<<(i-1))) == 0) && j == 0) continue;
				int nj = j;
				if(k == 0 && ((x&(1LL<<(i-1))) != 0)) nj = 1;
				dp[i-1][nj] += dp[i][j];
			}
		}
	}
	
	/*for(int i = 61; i >= 0; i--){
		for(int j = 0; j < 2; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	return dp[0][0] + dp[0][1];
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> l >> r;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	if(!dfs(1, n, 60)){
		cout << 0 << endl;
		return 0;
	}
	
	cout << calc(r) - calc(l-1) << endl;
	
	return 0;
}
0