結果

問題 No.911 ラッキーソート
ユーザー 👑 emthrmemthrm
提出日時 2019-10-18 22:26:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 3,787 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 127,400 KB
実行使用メモリ 5,668 KB
最終ジャッジ日時 2023-09-08 00:04:10
合計ジャッジ時間 5,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 56 ms
5,380 KB
testcase_14 AC 58 ms
5,248 KB
testcase_15 AC 56 ms
5,372 KB
testcase_16 AC 58 ms
5,552 KB
testcase_17 AC 59 ms
5,400 KB
testcase_18 AC 59 ms
5,384 KB
testcase_19 AC 61 ms
5,440 KB
testcase_20 AC 57 ms
5,252 KB
testcase_21 AC 61 ms
5,396 KB
testcase_22 AC 60 ms
5,456 KB
testcase_23 AC 59 ms
5,276 KB
testcase_24 AC 53 ms
5,072 KB
testcase_25 AC 32 ms
4,652 KB
testcase_26 AC 29 ms
4,380 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 57 ms
5,372 KB
testcase_39 AC 62 ms
5,388 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 58 ms
5,588 KB
testcase_42 AC 40 ms
4,716 KB
testcase_43 AC 55 ms
5,668 KB
testcase_44 AC 36 ms
4,668 KB
testcase_45 AC 38 ms
4,636 KB
testcase_46 AC 39 ms
4,636 KB
testcase_47 AC 39 ms
4,564 KB
testcase_48 AC 38 ms
4,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  int n; long long l, r; cin >> n >> l >> r;
  vector<long long> a(n); REP(i, n) cin >> a[i];
  vector<int> digit(61, -1), sec{0, n};
  for (int bit = 60; bit >= 0; --bit) {
    // for (int e : sec) cout << e << ' ';
    // cout << '\n';
    vector<int> nx;
    if (!sec.empty()) {
      for (int i = 0; i < sec.size(); i += 2) {
        int l = sec[i], r = sec[i + 1];
        if (a[l] >> bit & 1) {
          int zero = -1;
          FOR(j, l + 1, r) {
            if (!(a[j] >> bit & 1)) {
              if (zero == -1) zero = j;
            } else {
              if (zero != -1) {
                cout << 0 << '\n';
                return 0;
              }
            }
          }
          if (zero == -1) {
            nx.emplace_back(l);
            nx.emplace_back(r);
          } else {
            if (digit[bit] == 0) {
              cout << 0 << '\n';
              return 0;
            }
            digit[bit] = 1;
            if (zero - l > 1) {
              nx.emplace_back(l);
              nx.emplace_back(zero);
            }
            if (r - zero > 1) {
              nx.emplace_back(zero);
              nx.emplace_back(r);
            }
          }
        } else {
          int zero = -1;
          FOR(j, l + 1, r) {
            if (!(a[j] >> bit & 1)) {
              if (zero != -1) {
                cout << 0 << '\n';
                return 0;
              }
            } else {
              if (zero == -1) zero = j;
            }
          }
          if (zero == -1) {
            nx.emplace_back(l);
            nx.emplace_back(r);
          } else {
            if (digit[bit] == 1) {
              cout << 0 << '\n';
              return 0;
            }
            digit[bit] = 0;
            if (zero - l > 1) {
              nx.emplace_back(l);
              nx.emplace_back(zero);
            }
            if (r - zero > 1) {
              nx.emplace_back(zero);
              nx.emplace_back(r);
            }
          }
        }
      }
    }
    swap(sec, nx);
  }
  long long dp[62][2][2] = {};
  dp[61][false][false] = 1;
  for (int i = 60; i >= 0; --i) REP(j, 2) REP(k, 2) {
    if (digit[i] == 0 || digit[i] == -1) {
      if (j == 1 || !(l >> i & 1)) {
        bool nx_k = k;
        nx_k |= (r >> i & 1);
        dp[i][j][nx_k] += dp[i + 1][j][k];
      }
    }
    if (digit[i] == 1 || digit[i] == -1) {
      if (k == 1 || (r >> i & 1)) {
        bool nx_j = j;
        nx_j |= !(l >> i & 1);
        dp[i][nx_j][k] += dp[i + 1][j][k];
      }
    }
  }
  long long ans = 0;
  REP(j, 2) REP(k, 2) ans += dp[0][j][k];
  cout << ans << '\n';
  return 0;
}
0