結果

問題 No.911 ラッキーソート
ユーザー 👑 jupirojupiro
提出日時 2020-02-15 19:37:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 2,147 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 114,876 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-16 03:16:43
合計ジャッジ時間 7,047 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 112 ms
5,376 KB
testcase_14 AC 114 ms
5,376 KB
testcase_15 AC 114 ms
5,376 KB
testcase_16 AC 119 ms
5,376 KB
testcase_17 AC 118 ms
5,376 KB
testcase_18 AC 120 ms
5,376 KB
testcase_19 AC 119 ms
5,376 KB
testcase_20 AC 122 ms
5,376 KB
testcase_21 AC 125 ms
5,376 KB
testcase_22 AC 123 ms
5,376 KB
testcase_23 AC 124 ms
5,376 KB
testcase_24 AC 111 ms
5,376 KB
testcase_25 AC 69 ms
5,376 KB
testcase_26 AC 57 ms
5,376 KB
testcase_27 AC 28 ms
5,376 KB
testcase_28 AC 14 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 113 ms
5,376 KB
testcase_39 AC 122 ms
5,376 KB
testcase_40 AC 4 ms
5,376 KB
testcase_41 AC 119 ms
5,376 KB
testcase_42 AC 54 ms
5,376 KB
testcase_43 AC 115 ms
5,376 KB
testcase_44 AC 42 ms
5,504 KB
testcase_45 AC 43 ms
5,376 KB
testcase_46 AC 41 ms
5,376 KB
testcase_47 AC 42 ms
5,376 KB
testcase_48 AC 40 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll N, L, R;
ll a[200500];

ll dfs(ll X) {
	ll dp[63][2]; for (ll i = 0; i < 63; i++) for (ll j = 0; j < 2; j++) dp[i][j] = 0;
	dp[62][1] = 1;
	vector<bool> used(N, false);
	for (ll i = 61; i >= 0; i--) {
		ll tmp = -1;
		for (ll j = 0; j < N - 1; j++) {
			if (used[j]) continue;
			ll lf = (a[j] >> i & 1);
			ll rg = (a[j + 1] >> i & 1);
			if (lf == rg) continue;
			if (lf == 1) {
				if (tmp == -1) tmp = 1;
				else if (tmp == 0) {
					return 0;
				}
			}
			else {
				if (tmp == -1) tmp = 0;
				else if (tmp == 1) {
					return 0;
				}
			}
			used[j] = true;
		}
		if (tmp == -1) {
			dp[i][1] += dp[i + 1][1];
			if(X >> i & 1) dp[i][0] += dp[i + 1][1];
			dp[i][0] += dp[i + 1][0] * 2;
		}
		else if (tmp == 1) {
			if (X >> i & 1) {
				dp[i][1] += dp[i + 1][1];
			}
			dp[i][0] += dp[i + 1][0];
		}
		else {
			//cout << i << endl;
			if (!(X >> i & 1)) {
				dp[i][1] += dp[i + 1][1];
			}
			else {
				dp[i][0] += dp[i + 1][1];
			}
			dp[i][0] += dp[i + 1][0];
		}
	}
	return dp[0][0] + dp[0][1];

}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld %lld %lld", &N, &L, &R);
	for (ll i = 0; i < N; i++) scanf("%lld", &a[i]);
	ll res = dfs(R);
	//cout << res << endl;
	if (L) res -= dfs(L - 1);
	cout << res << endl;
	return 0;
}
0