結果
問題 | No.911 ラッキーソート |
ユーザー | damenin27844103 |
提出日時 | 2019-10-19 14:15:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,934 bytes |
コンパイル時間 | 1,250 ms |
コンパイル使用メモリ | 123,680 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-27 03:45:40 |
合計ジャッジ時間 | 7,982 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 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 | 1 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | AC | 20 ms
5,376 KB |
testcase_18 | WA | - |
testcase_19 | AC | 20 ms
5,376 KB |
testcase_20 | RE | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | AC | 63 ms
6,272 KB |
testcase_27 | AC | 23 ms
5,376 KB |
testcase_28 | AC | 12 ms
5,376 KB |
testcase_29 | AC | 6 ms
5,376 KB |
testcase_30 | AC | 3 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 | 3 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | AC | 6 ms
5,376 KB |
testcase_41 | AC | 21 ms
5,376 KB |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | AC | 19 ms
5,376 KB |
testcase_48 | RE | - |
ソースコード
#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 = 100000; int N; ll L, R; ll A[MAX_N]; int bitmap[61]; void set_bitmap(); ll max_x(); ll min_x(); int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); 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; } }