結果

問題 No.911 ラッキーソート
ユーザー 沙耶花沙耶花
提出日時 2019-10-18 23:05:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 2,074 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 174,196 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-09-08 01:44:57
合計ジャッジ時間 8,036 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 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,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 167 ms
4,620 KB
testcase_14 AC 171 ms
4,576 KB
testcase_15 AC 172 ms
4,616 KB
testcase_16 AC 176 ms
4,684 KB
testcase_17 AC 174 ms
4,532 KB
testcase_18 AC 175 ms
4,632 KB
testcase_19 AC 173 ms
4,532 KB
testcase_20 AC 174 ms
4,644 KB
testcase_21 AC 174 ms
4,628 KB
testcase_22 AC 171 ms
4,532 KB
testcase_23 AC 163 ms
4,380 KB
testcase_24 AC 149 ms
4,376 KB
testcase_25 AC 92 ms
4,376 KB
testcase_26 AC 73 ms
4,380 KB
testcase_27 AC 35 ms
4,376 KB
testcase_28 AC 18 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 173 ms
4,572 KB
testcase_39 AC 169 ms
4,376 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 173 ms
4,580 KB
testcase_42 AC 110 ms
4,376 KB
testcase_43 AC 172 ms
4,676 KB
testcase_44 AC 129 ms
4,580 KB
testcase_45 AC 131 ms
4,572 KB
testcase_46 AC 132 ms
4,588 KB
testcase_47 AC 129 ms
4,532 KB
testcase_48 AC 126 ms
4,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

long long DP(vector<int> B,long long M){
	vector<vector<long long>> dp(61,vector<long long>(2,0));
	for(int i=60;i>=0;i--){
		if(i==60){
			if(B[i]==-1){
				if(M&((long long)1<<i)){
					dp[i][0]=1;
					dp[i][1]=1;
				}
				else{
					dp[i][0]=1;
				}
			}
			if(B[i]==0){
				if(M&((long long)1<<i)){
					dp[i][1]=1;
				}
				else{
					dp[i][0]=1;
				}
			}
			if(B[i]==1){
				if(M&((long long)1<<i)){
					dp[i][0]=1;
				}
			}
		}
		else{
			if(B[i]==-1){
				if(M&((long long)1<<i)){
					dp[i][0]=dp[i+1][0];
					dp[i][1]=dp[i+1][0]+2*dp[i+1][1];
				}
				else{
					dp[i][0]=dp[i+1][0];
					dp[i][1]=2*dp[i+1][1];
				}
			}
			if(B[i]==0){
				if(M&((long long)1<<i)){
					dp[i][1] = dp[i+1][0]+dp[i+1][1];
				}
				else{
					dp[i][0]=dp[i+1][0];
					dp[i][1]=dp[i+1][1];
				}
			}
			if(B[i]==1){
				if(M&((long long)1<<i)){
					dp[i][0]=dp[i+1][0];
					dp[i][1]=dp[i+1][1];
				}
				else{
					dp[i][1]=dp[i+1][1];
				}
			}
		}
	}
	
	for(int i=0;i<4;i++){
		//cout<<dp[i][0]<<','<<dp[i][1]<<endl;
		//cout<<B[i]<<endl;
	}
	
	return dp[0][0]+dp[0][1];
}

int main(){
	
	int N;
	cin>>N;
	
	long long L,R;
	cin>>L>>R;
	
	vector<long long> A(N);
	
	for(int i=0;i<N;i++){
		cin>>A[i];
		//cout<<(bitset<12>)A[i]<<endl;
	}
	
	
	if(N==1){
		cout<<R-L+1<<endl;
		return 0;
	}
	
	vector<bool> ok(N,false);
	ok[0]=true;
	
	vector<int> B(61,-1);

	for(int i=60;i>=0;i--){
		bool f1 = true;
		bool f2 = true;
		for(int j=1;j<N;j++){
			if(ok[j])continue;
			bool a = (A[j-1] & ((long long)1<<i));
			bool b = (A[j] & ((long long)1<<i));
			if(a&&!b)f1=false;
			if(b&&!a)f2=false;
			if(a!=b)ok[j]=true;
		}
		if(!f1&&!f2){
			cout<<0<<endl;
			return 0;
		}
		
		if(f1&&!f2)B[i]=0;
		if(f2&&!f1)B[i]=1;
		
		bool f = true;
		for(int j=0;j<N;j++){
			if(!ok[j]){
				f=false;
				break;
			}
		}
		if(f)break;
	}

	
	
	if(L!=0)cout<<DP(B,R)-DP(B,L-1)<<endl;
	else cout<<DP(B,R)<<endl;
	
    return 0;
}
0