結果

問題 No.911 ラッキーソート
ユーザー kwm_tkwm_t
提出日時 2023-05-13 15:26:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,810 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 205,920 KB
実行使用メモリ 4,760 KB
最終ジャッジ日時 2023-08-19 14:36:11
合計ジャッジ時間 9,469 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 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,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 58 ms
4,612 KB
testcase_14 AC 59 ms
4,528 KB
testcase_15 AC 60 ms
4,668 KB
testcase_16 AC 61 ms
4,652 KB
testcase_17 AC 60 ms
4,608 KB
testcase_18 AC 60 ms
4,648 KB
testcase_19 AC 60 ms
4,608 KB
testcase_20 AC 61 ms
4,588 KB
testcase_21 AC 65 ms
4,572 KB
testcase_22 AC 65 ms
4,612 KB
testcase_23 AC 61 ms
4,376 KB
testcase_24 AC 55 ms
4,380 KB
testcase_25 AC 37 ms
4,376 KB
testcase_26 AC 26 ms
4,380 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 60 ms
4,564 KB
testcase_39 AC 63 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 62 ms
4,668 KB
testcase_42 AC 33 ms
4,380 KB
testcase_43 AC 59 ms
4,616 KB
testcase_44 AC 42 ms
4,760 KB
testcase_45 AC 45 ms
4,568 KB
testcase_46 AC 40 ms
4,576 KB
testcase_47 AC 43 ms
4,572 KB
testcase_48 AC 41 ms
4,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	long long l, r; cin >> l >> r;
	vector<long long>a(n);
	rep(i, n)cin >> a[i];
	auto f = [&](long long mx)->long long {
		if (mx < 0)return 0;
		vector<int>need(61, -1);
		rep(i, n - 1) {
			rrep(j, 61) {
				int x = 1 & (a[i + 0] >> j);
				int y = 1 & (a[i + 1] >> j);
				if (x == y)continue;
				if (-1 == need[60 - j]) need[60 - j] = x > y;
				else if (need[60 - j] != (x > y)) return 0;
				break;
			}
		}

		vector dp(62, vector<long long>(2));//未満が1
		dp[0][0] = 1;
		rep(i, 61) {
			vector<int> num;
			if (-1 == need[i]) num = { 1,0 };
			else num = { need[i] };
			rep(j, 2) {
				int k = 1 & (mx >> (60 - i));
				rep(l, num.size()) {
					int nx = num[l];
					if (!j && k < nx) continue;
					int nj = !(!j && (k == nx));
					dp[i + 1][nj] += dp[i][j];
				}
			}
		}
		return dp[61][1] + dp[61][0];
	};
	long long ans = f(r) - f(l - 1);
	cout << ans << endl;
	return 0;
}
0