結果

問題 No.911 ラッキーソート
ユーザー sigma425sigma425
提出日時 2019-10-18 21:59:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,694 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 204,844 KB
実行使用メモリ 4,708 KB
最終ジャッジ日時 2023-09-07 22:25:04
合計ジャッジ時間 6,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 52 ms
4,708 KB
testcase_14 AC 53 ms
4,684 KB
testcase_15 AC 51 ms
4,704 KB
testcase_16 AC 54 ms
4,696 KB
testcase_17 AC 53 ms
4,564 KB
testcase_18 AC 53 ms
4,620 KB
testcase_19 AC 53 ms
4,564 KB
testcase_20 AC 53 ms
4,568 KB
testcase_21 AC 54 ms
4,564 KB
testcase_22 AC 55 ms
4,704 KB
testcase_23 AC 50 ms
4,376 KB
testcase_24 AC 46 ms
4,380 KB
testcase_25 AC 30 ms
4,380 KB
testcase_26 AC 23 ms
4,380 KB
testcase_27 AC 12 ms
4,380 KB
testcase_28 AC 7 ms
4,376 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 53 ms
4,580 KB
testcase_39 AC 52 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 53 ms
4,568 KB
testcase_42 AC 35 ms
4,376 KB
testcase_43 AC 53 ms
4,700 KB
testcase_44 AC 52 ms
4,696 KB
testcase_45 AC 53 ms
4,568 KB
testcase_46 AC 53 ms
4,704 KB
testcase_47 AC 53 ms
4,620 KB
testcase_48 AC 53 ms
4,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif
bool B(ll x,int i){return (x>>i)&1;}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	ll L,R;
	cin >> N >> L >> R;
	V<ll> A(N);
	rep(i,N) cin >> A[i];
	auto solve = [&](ll X){	// <X
		V<ll> d(62,0);
		rep(i,N-1){
			ll a = A[i], b = A[i+1];
			for(int j=61;j>=0;j--) if(B(a^b,j)){
				if(B(a,j)) d[j] |= 2;
				else d[j] |= 1;
				break;
			}
		}
		rep(i,62) if(d[i] == 3) return 0LL;
		rep(i,62) d[i]--;
		show(d);
		V<ll> dp = {1,0};
		for(int i=61;i>=0;i--){
			V<ll> ndp(2);
			rep(j,2){
				rep(x,2){
					if(x != d[i] && d[i] != -1) continue;
					if(j == 0 && x == 1 && !B(X,i)) continue;
					int nj = j;
					if(j == 0 && x != B(X,i)) nj = 1;
					ndp[nj] += dp[j];
				}
			}
			dp = ndp;
		}
		return dp[1];
	};
	cout << solve(R+1) - solve(L) << endl;
}
0