結果

問題 No.911 ラッキーソート
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-10-19 08:44:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,504 ms / 2,000 ms
コード長 3,426 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 206,892 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-09-08 17:53:54
合計ジャッジ時間 26,989 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,504 ms
7,904 KB
testcase_14 AC 1,474 ms
7,844 KB
testcase_15 AC 1,415 ms
7,844 KB
testcase_16 AC 1,423 ms
7,752 KB
testcase_17 AC 1,457 ms
7,900 KB
testcase_18 AC 1,412 ms
7,768 KB
testcase_19 AC 1,420 ms
7,860 KB
testcase_20 AC 1,287 ms
7,988 KB
testcase_21 AC 1,092 ms
7,872 KB
testcase_22 AC 969 ms
7,708 KB
testcase_23 AC 952 ms
7,736 KB
testcase_24 AC 836 ms
7,532 KB
testcase_25 AC 440 ms
5,524 KB
testcase_26 AC 440 ms
5,312 KB
testcase_27 AC 156 ms
4,376 KB
testcase_28 AC 77 ms
4,380 KB
testcase_29 AC 31 ms
4,380 KB
testcase_30 AC 6 ms
4,384 KB
testcase_31 AC 3 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1,459 ms
8,004 KB
testcase_39 AC 962 ms
7,652 KB
testcase_40 AC 15 ms
4,500 KB
testcase_41 AC 1,309 ms
7,876 KB
testcase_42 AC 363 ms
5,640 KB
testcase_43 AC 1,473 ms
7,904 KB
testcase_44 AC 46 ms
6,408 KB
testcase_45 AC 46 ms
6,404 KB
testcase_46 AC 43 ms
6,116 KB
testcase_47 AC 46 ms
6,488 KB
testcase_48 AC 40 ms
6,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<pair<int, int>> runLengthEncoding(vector<int> s) {
	int n = s.size();

	vector<pair<int, int>> res;
	int pre = s[0];
	int cnt = 1;
	rep(i, 1, n) {
		if (pre != s[i]) {
			res.push_back({ pre, cnt });
			pre = s[i];
			cnt = 1;
		}
		else cnt++;
	}

	res.push_back({ pre, cnt });
	return res;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; ll L, R, A[201010];
//---------------------------------------------------------------------------------------------------
ll dp[62][2];
ll solve(ll X) {
	if (X < 0) return 0;

	rep(dgt, 0, 62) rep(isless, 0, 2) dp[dgt][isless] = 0;
	dp[0][0] = 1;

	vector<int> grp;
	grp.push_back(0);
	grp.push_back(N);

	rep(dgt, 0, 61) {
		int n = grp.size();
		ll msk = 1LL << (60 - dgt);

		int f0 = 0, f1 = 0, f01 = 0;

		vector<int> grp2;
		rep(i, 0, n - 1) {
			int l = grp[i];
			int r = grp[i + 1];

			vector<int> v01;
			rep(i, l, r) {
				if (A[i] & msk) v01.push_back(1);
				else v01.push_back(0);
			}

			auto v01run = runLengthEncoding(v01);
			if (v01run.size() == 1) {
				f01++;
				grp2.push_back(l);
			}
			else if (v01run.size() == 2) {
				if (v01run[0].first == 0) f0++;
				else f1++;

				grp2.push_back(l);
				grp2.push_back(l + v01run[0].second);
			}
			else return 0;
		}
		grp2.push_back(N);
		swap(grp, grp2);

		if (0 < f0 and 0 < f1) return 0;

		int cur_dgt = 0;
		if (X & msk) cur_dgt = 1;

		vector<int> v_nxt;

		if (0 < f0) {
			// 0じゃないとだめ
			v_nxt.push_back(0);
		}
		else if (0 < f1) {
			// 1じゃないとだめ
			v_nxt.push_back(1);
		}
		else {
			// 0でも1でもいいよ
			v_nxt.push_back(0);
			v_nxt.push_back(1);
		}

		rep(isless, 0, 2) fore(nxt, v_nxt) {
			if (!isless and cur_dgt < nxt) continue;
			int isless2 = isless;
			if (nxt < cur_dgt) isless2 = 1;
			dp[dgt + 1][isless2] += dp[dgt][isless];
		}
	}

	return dp[61][0] + dp[61][1];
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> L >> R;
	rep(i, 0, N) cin >> A[i];

	ll ans = solve(R) - solve(L - 1);
	cout << ans << endl;
}





0