結果

問題 No.911 ラッキーソート
ユーザー square1001square1001
提出日時 2019-10-18 22:07:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 698 ms
コンパイル使用メモリ 75,312 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-09-07 23:35:27
合計ジャッジ時間 6,080 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 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,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 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 131 ms
4,624 KB
testcase_14 AC 134 ms
4,692 KB
testcase_15 AC 133 ms
4,752 KB
testcase_16 AC 137 ms
4,584 KB
testcase_17 AC 137 ms
4,696 KB
testcase_18 AC 137 ms
4,584 KB
testcase_19 AC 135 ms
4,548 KB
testcase_20 AC 133 ms
4,696 KB
testcase_21 AC 134 ms
4,732 KB
testcase_22 AC 131 ms
4,656 KB
testcase_23 AC 121 ms
4,380 KB
testcase_24 AC 112 ms
4,376 KB
testcase_25 AC 71 ms
4,376 KB
testcase_26 AC 53 ms
4,380 KB
testcase_27 AC 27 ms
4,376 KB
testcase_28 AC 14 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 137 ms
4,596 KB
testcase_39 AC 128 ms
4,468 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 133 ms
4,880 KB
testcase_42 AC 80 ms
4,376 KB
testcase_43 AC 136 ms
4,916 KB
testcase_44 AC 128 ms
4,732 KB
testcase_45 AC 126 ms
4,628 KB
testcase_46 AC 126 ms
4,600 KB
testcase_47 AC 126 ms
4,548 KB
testcase_48 AC 127 ms
4,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <functional>
using namespace std;
int main() {
	int N; long long L, R;
	cin >> N >> L >> R;
	vector<long long> A(N);
	string cond(62, '?');
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	bool ok = true;
	for (int i = 0; i < N - 1; ++i) {
		if (A[i] == A[i + 1]) {
			ok = false;
			break;
		}
		int d = 61;
		while (!(((A[i] ^ A[i + 1]) >> d) & 1)) --d;
		if (A[i] < A[i + 1]) {
			if (cond[d] == '1') {
				ok = false;
				break;
			}
			cond[d] = '0';
		}
		else {
			if (cond[d] == '0') {
				ok = false;
				break;
			}
			cond[d] = '1';
		}
	}
	function<long long(long long)> calc = [&](long long x) {
		long long cur = 0, ans = 0;
		for (int i = 61; i >= 0; --i) {
			if (cur + (1LL << i) <= x) {
				cur += 1LL << i;
				if (cond[i] == '1') continue;
				int cnt = 0;
				for (int j = 0; j < i; ++j) {
					if (cond[j] == '?') ++cnt;
				}
				ans += 1LL << cnt;
				if (cond[i] == '0') break;
			}
			else if (cond[i] == '1') break;
		}
		return ans;
	};
	if (!ok) {
		cout << 0 << endl;
	}
	else {
		long long cl = calc(L);
		long long cr = calc(R + 1);
		cout << cr - cl << endl;
	}
	return 0;
}
0