結果

問題 No.911 ラッキーソート
ユーザー satashunsatashun
提出日時 2019-10-18 21:54:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,900 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 170,252 KB
実行使用メモリ 4,788 KB
最終ジャッジ日時 2023-09-07 22:07:22
合計ジャッジ時間 7,612 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 138 ms
4,788 KB
testcase_14 AC 141 ms
4,616 KB
testcase_15 WA -
testcase_16 AC 144 ms
4,636 KB
testcase_17 AC 143 ms
4,548 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 140 ms
4,604 KB
testcase_21 AC 141 ms
4,728 KB
testcase_22 WA -
testcase_23 AC 124 ms
4,376 KB
testcase_24 AC 113 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 15 ms
4,380 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 2 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 WA -
testcase_38 AC 135 ms
4,724 KB
testcase_39 AC 129 ms
4,380 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 138 ms
4,652 KB
testcase_42 AC 87 ms
4,376 KB
testcase_43 AC 134 ms
4,640 KB
testcase_44 AC 125 ms
4,784 KB
testcase_45 AC 129 ms
4,724 KB
testcase_46 AC 124 ms
4,716 KB
testcase_47 AC 123 ms
4,656 KB
testcase_48 AC 119 ms
4,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int sz = 62;

ll calc(ll x, V<int> vec) {
	if (x == 0) return 0ll;
	ll res = 0;
	V<int> fr(sz);
	for (int i = sz - 1; i >= 0; --i) {
		for (int j = i-1; j >= 0; --j) {
			if (vec[j] == -1) {
				++fr[i];
			}
		}
	}

	bool sm = 1;

	for (int i = sz - 1; i >= 0; --i) {
		ll f = (x >> i) & 1;
		if (sm && vec[i] != -1 && vec[i] > f) {
			break;
		}
		if (vec[i] != -1 && vec[i] < f) {
			sm = 0;
		}

		if (f && vec[i] != 1) {
			res += 1LL << fr[i];
		}
	}
	return res;
}

int main() {
	int N; ll L, R; cin >> N >> L >> R;
	V<ll> vec(N);
	rep(i, N) cin >> vec[i];
	V<int> col(sz, -1);

	rep(i, N-1) {
		for (int j = sz - 1; j >= 0; --j) {
			if (((vec[i]>>j)&1) != ((vec[i+1]>>j)&1)) {
				int c = ((vec[i]>>j)&1);
				if (col[j] == (c ^ 1)) {
					puts("0");
					return 0;
				}
				if (c == 0) {
					col[j] = 0;
				} else {
					col[j] = 1;
				}
				break;
			}
		}
	}

	cout << calc(R+1, col) - calc(L, col) << endl;

	return 0;
}
0