結果

問題 No.911 ラッキーソート
ユーザー 👑 jupirojupiro
提出日時 2020-04-17 05:14:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,939 bytes
コンパイル時間 1,314 ms
コンパイル使用メモリ 123,804 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 12:25:04
合計ジャッジ時間 6,427 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 51 ms
6,944 KB
testcase_14 AC 52 ms
6,944 KB
testcase_15 AC 53 ms
6,940 KB
testcase_16 AC 53 ms
6,940 KB
testcase_17 AC 52 ms
6,944 KB
testcase_18 AC 52 ms
6,940 KB
testcase_19 AC 53 ms
6,944 KB
testcase_20 AC 53 ms
6,940 KB
testcase_21 AC 55 ms
6,944 KB
testcase_22 AC 54 ms
6,944 KB
testcase_23 AC 50 ms
6,940 KB
testcase_24 AC 46 ms
6,944 KB
testcase_25 AC 30 ms
6,944 KB
testcase_26 AC 23 ms
6,944 KB
testcase_27 AC 12 ms
6,940 KB
testcase_28 AC 7 ms
6,940 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 53 ms
6,940 KB
testcase_39 AC 53 ms
6,944 KB
testcase_40 AC 3 ms
6,944 KB
testcase_41 AC 53 ms
6,940 KB
testcase_42 AC 36 ms
6,940 KB
testcase_43 AC 51 ms
6,940 KB
testcase_44 AC 51 ms
6,944 KB
testcase_45 AC 54 ms
6,940 KB
testcase_46 AC 53 ms
6,940 KB
testcase_47 AC 52 ms
6,940 KB
testcase_48 AC 52 ms
6,940 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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

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

ll N, L, R;
vector<ll> a;
vector<vector<int>> can;
ll solve(ll x) {
	vector<vector<ll>> dp(63, vector<ll>(2));
	dp[62][1] = 1;
	for (int bit = 61; bit >= 0; bit--) {
		int t = (x >> bit) & 1;
		if (t == 1) {
			dp[bit][1] += dp[bit + 1][1] * can[bit][1];
			dp[bit][0] += dp[bit + 1][1] * can[bit][0];
		}
		else {
			dp[bit][1] += dp[bit + 1][1] * can[bit][0];
		}
		dp[bit][0] += dp[bit + 1][0] * (can[bit][0] + can[bit][1]);
	}
	return dp[0][0] + dp[0][1];
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld %lld %lld", &N, &L, &R);
	a.resize(N); for (int i = 0; i < N; i++) scanf("%lld", &a[i]);
	can = vector<vector<int>>(63, vector<int>(2, 1));
	for (int i = 0; i < N - 1; i++) {
		for (int j = 62; j >= 0; j--) {
			int s = a[i] >> j & 1;
			int t = a[i + 1] >> j & 1;
			if (s == 1 and t == 0) {
				can[j][0] = 0;
				break;
			}
			if (s == 0 and t == 1) {
				can[j][1] = 0;
				break;
			}
		}
	}
	ll res = solve(R);
	if (L) res -= solve(L - 1);
	cout << res << endl;
    return 0;
} 
0