結果

問題 No.911 ラッキーソート
ユーザー kotamanegikotamanegi
提出日時 2019-10-18 21:55:25
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 2,183 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 113,336 KB
実行使用メモリ 5,276 KB
最終ジャッジ日時 2023-08-20 13:04:07
合計ジャッジ時間 10,412 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 143 ms
5,184 KB
testcase_14 AC 145 ms
5,160 KB
testcase_15 AC 140 ms
5,176 KB
testcase_16 AC 149 ms
5,184 KB
testcase_17 AC 146 ms
5,264 KB
testcase_18 AC 144 ms
5,268 KB
testcase_19 AC 155 ms
5,276 KB
testcase_20 AC 148 ms
5,236 KB
testcase_21 AC 164 ms
5,264 KB
testcase_22 AC 161 ms
5,184 KB
testcase_23 AC 134 ms
5,260 KB
testcase_24 AC 128 ms
5,220 KB
testcase_25 AC 81 ms
4,380 KB
testcase_26 AC 58 ms
4,380 KB
testcase_27 AC 29 ms
4,384 KB
testcase_28 AC 16 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 147 ms
5,176 KB
testcase_39 AC 149 ms
5,264 KB
testcase_40 AC 5 ms
4,504 KB
testcase_41 AC 150 ms
5,212 KB
testcase_42 AC 85 ms
4,376 KB
testcase_43 AC 143 ms
5,212 KB
testcase_44 AC 145 ms
5,212 KB
testcase_45 AC 146 ms
5,228 KB
testcase_46 AC 141 ms
5,264 KB
testcase_47 AC 144 ms
5,268 KB
testcase_48 AC 129 ms
5,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//カタラン数を語らん!w

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long n, l, r;
vector<long long> inputs;
long long calc(long long now) {
	long long must_be[64][2] = {};
	for (long long i = 0; i < inputs.size() - 1; ++i) {
		for (long long q = 61; q >= 0; --q) {
			long long a = ((1LL << q) & inputs[i]);
			long long b = ((1LL << q) & inputs[i + 1]);
			if ((a ^ b) != 0) {
				if (a != 0) {
					must_be[q][1] = 1;
				}
				else {
					must_be[q][0] = 1;
					//bit
				}
				break;
			}
		}
	}
	long long cnt = 0;
	long long ans = 0;
	for (long long i = 61; i >= 0; --i) {
		if (must_be[i][0] + must_be[i][1] == 2) return 0;
		if (must_be[i][0] + must_be[i][1] == 1) {

		}
		else {
			cnt++;
		}
	}
	for (long long q = 61; q >= 0; --q) {
		if (must_be[q][0] + must_be[q][1] == 0) cnt--;
		if (((1LL << q) & now) == 0) {
			//should be 0
			if (must_be[q][1] == 1) {
				return ans;
			}
		}
		else {
			//can be both 0 & 1
			if (must_be[q][0] == 1) {
				return ans + (1LL << cnt);
			}
			else {
				if (must_be[q][1] == 0) {
					ans += 1LL << cnt;
				}
			}
		}
	}
	return ans + 1LL;
}
int main() {
	cin >> n >> l >> r;
	REP(i, n) {
		long long a;
		cin >> a;
		inputs.push_back(a);
	}
	long long ans = calc(r);
	if (l != 0) {
		ans -= calc(l - 1);
	}
	cout << ans << endl;
}
0