結果
問題 | No.911 ラッキーソート |
ユーザー | damenin27844103 |
提出日時 | 2019-10-19 14:34:25 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 292 ms / 2,000 ms |
コード長 | 5,875 bytes |
コンパイル時間 | 1,181 ms |
コンパイル使用メモリ | 123,000 KB |
実行使用メモリ | 12,080 KB |
最終ジャッジ日時 | 2024-06-27 04:11:11 |
合計ジャッジ時間 | 8,986 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 290 ms
12,036 KB |
testcase_14 | AC | 291 ms
12,028 KB |
testcase_15 | AC | 279 ms
12,028 KB |
testcase_16 | AC | 285 ms
11,964 KB |
testcase_17 | AC | 289 ms
12,028 KB |
testcase_18 | AC | 281 ms
12,024 KB |
testcase_19 | AC | 281 ms
12,016 KB |
testcase_20 | AC | 257 ms
11,996 KB |
testcase_21 | AC | 250 ms
11,856 KB |
testcase_22 | AC | 222 ms
11,832 KB |
testcase_23 | AC | 225 ms
10,564 KB |
testcase_24 | AC | 204 ms
9,192 KB |
testcase_25 | AC | 113 ms
7,508 KB |
testcase_26 | AC | 98 ms
6,508 KB |
testcase_27 | AC | 41 ms
5,376 KB |
testcase_28 | AC | 21 ms
5,376 KB |
testcase_29 | AC | 8 ms
5,376 KB |
testcase_30 | AC | 2 ms
5,376 KB |
testcase_31 | AC | 2 ms
5,376 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 2 ms
5,376 KB |
testcase_34 | AC | 2 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 1 ms
5,376 KB |
testcase_38 | AC | 292 ms
12,028 KB |
testcase_39 | AC | 225 ms
11,648 KB |
testcase_40 | AC | 7 ms
5,376 KB |
testcase_41 | AC | 258 ms
11,860 KB |
testcase_42 | AC | 155 ms
7,736 KB |
testcase_43 | AC | 290 ms
12,080 KB |
testcase_44 | AC | 135 ms
5,376 KB |
testcase_45 | AC | 135 ms
5,376 KB |
testcase_46 | AC | 136 ms
5,376 KB |
testcase_47 | AC | 137 ms
5,376 KB |
testcase_48 | AC | 131 ms
5,376 KB |
ソースコード
#include <iostream> #include <algorithm> #include <bitset> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <cstring> #include <utility> #include <vector> #include <complex> #include <valarray> #include <fstream> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <climits> #include <random> #define _overload(a, b, c, d, ...) d #define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X)) #define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X)) #define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__) #define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X)) #define all(X) (X).begin(),(X).end() #define len(X) ((int)(X).size()) #define mod(n, m) (((n)%(m)+(m))%m) #define fi first #define sc second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; const int INFINT = 1 << 30; // 1.07x10^ 9 const ll INFLL = 1LL << 60; // 1.15x10^18 const double EPS = 1e-10; const int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const int MAX_N = 200000; int N; ll L, R; ll A[MAX_N]; int bitmap[61]; void set_bitmap(); ll max_x(); ll min_x(); int main() { cin >> N >> L >> R; rep(i, N) cin >> A[i]; set_bitmap(); ll ma = max_x(); ll mi = min_x(); if (ma < L) { cout << 0 << endl; } else if (mi > R) { cout << 0 << endl; } else { ll mi_bit = 0, ma_bit = 0; for (int i = 61; i >= 0; --i) { if (bitmap[i] == 2) { mi_bit <<= 1; ma_bit <<= 1; mi_bit |= ((mi>>i)&1); ma_bit |= ((ma>>i)&1); } } cout << ma_bit - mi_bit + 1 << endl; } return 0; } ll max_x() { ll res = 0; for (int i = 61; i >= 0; --i) { if (bitmap[i] == 1) { res += 1LL << i; } } if (res > R) return -1; for (int i = 61; i >= 0; --i) { if (bitmap[i] == 2) { ll tmp = res; tmp += 1LL << i; if (tmp <= R) { res = tmp; } } } return res; } ll min_x() { ll res = 0; for (int i = 61; i >= 0; --i) { if (bitmap[i] == 1) { res += 1LL << i; } } if (res >= L) return res; for (int i = 61; i >= 0; --i) { if (bitmap[i] == 2) { ll tmp = res; tmp += 1LL << i; if (tmp < L) res = tmp; } } int first_zero_bit = -1; for (int i = 0; i <= 61; ++i) { if ((bitmap[i] == 2) && ((res >> i) & 1) == 0) { first_zero_bit = i; break; } } if (first_zero_bit < 0) return INFLL; res += 1ll << first_zero_bit; for (int i = 0; i < first_zero_bit; ++i) { if (bitmap[i] == 2) { res -= 1ll << i; } } return res; } void set_bitmap() { vector<Pii> section; section.emplace_back(0, N); for (ll i = 61; i >= 0; --i) { vector<Pii> tmp_section; bool must_flag = false; bool must_not_flag = false; for (ll j = 0; j < len(section); ++j) { ll lb = section[j].fi; ll ub = section[j].sc; bool all_zero = true; for (ll k = lb; k < ub; ++k) { if (((A[k] >> i) & 1) == 1) { all_zero = false; break; } } if (all_zero) { tmp_section.emplace_back(Pii(lb, ub)); continue; } bool all_one = true; for (ll k = lb; k < ub; ++k) { if (((A[k] >> i) & 1) == 0) { all_one = false; break; } } if (all_one) { tmp_section.emplace_back(Pii(lb, ub)); continue; } ll first_one_index = 0; if (((A[lb] >> i) & 1) == 0) { for (ll k = lb; k < ub; ++k) { if (((A[k] >> i) & 1) == 1) { first_one_index = k; break; } } bool valid_section = true; for (ll k = first_one_index; k < ub; ++k) { if (((A[k] >> i) & 1) == 0) { valid_section = false; break; } } if (!valid_section) { cout << 0 << endl; exit(0); } must_not_flag = true; } else { for (ll k = lb; k < ub; ++k) { if (((A[k] >> i) & 1) == 0) { first_one_index = k; break; } } bool valid_section = true; for (ll k = first_one_index; k < ub; ++k) { if (((A[k] >> i) & 1) == 1) { valid_section = false; break; } } if (!valid_section) { cout << 0 << endl; exit(0); } must_flag = true; } tmp_section.emplace_back(lb, first_one_index); tmp_section.emplace_back(first_one_index, ub); } if (must_not_flag && must_flag) { cout << 0 << endl; exit(0); } else if (must_flag) { bitmap[i] = 1; } else if (must_not_flag) { bitmap[i] = 0; } else { bitmap[i] = 2; } section = tmp_section; } }