結果

問題 No.911 ラッキーソート
ユーザー NozeNoze
提出日時 2019-10-23 23:38:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 3,016 ms
コンパイル使用メモリ 92,808 KB
実行使用メモリ 4,800 KB
最終ジャッジ日時 2023-09-21 16:52:38
合計ジャッジ時間 8,895 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,508 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 54 ms
4,636 KB
testcase_14 AC 56 ms
4,616 KB
testcase_15 AC 56 ms
4,624 KB
testcase_16 AC 58 ms
4,620 KB
testcase_17 AC 57 ms
4,800 KB
testcase_18 AC 57 ms
4,520 KB
testcase_19 AC 57 ms
4,656 KB
testcase_20 AC 58 ms
4,520 KB
testcase_21 AC 59 ms
4,644 KB
testcase_22 AC 59 ms
4,696 KB
testcase_23 AC 57 ms
4,532 KB
testcase_24 AC 51 ms
4,536 KB
testcase_25 AC 34 ms
4,376 KB
testcase_26 AC 26 ms
4,376 KB
testcase_27 AC 14 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 56 ms
4,780 KB
testcase_39 AC 58 ms
4,640 KB
testcase_40 AC 3 ms
4,384 KB
testcase_41 AC 57 ms
4,644 KB
testcase_42 AC 39 ms
4,380 KB
testcase_43 AC 56 ms
4,636 KB
testcase_44 AC 54 ms
4,728 KB
testcase_45 AC 57 ms
4,624 KB
testcase_46 AC 56 ms
4,692 KB
testcase_47 AC 55 ms
4,516 KB
testcase_48 AC 57 ms
4,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, l, r;
  cin >> n >> l >> r;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  int mask[62] = {};
  rep(i, n-1) rep(j, 62) {
    if ((a[i]&1LL<<61-j) == 0 && a[i+1]&1LL<<61-j) {
      mask[j] |= 1;
      break;
    }
    if (a[i]&1LL<<61-j && (a[i+1]&1LL<<61-j) == 0) {
      mask[j] |= 2;
      break;
    }
  }
  rep(i, 62) {
    if (mask[i] == 3) {
      cout << 0 << endl;
      return 0;
    }
  }
  auto DP = [=](ll mx){
    ll dp[63][2] = {};
    dp[0][0] = 1;
    rep(i, 62) rep(j, 2) {
      int n = mx>>61-i&1;
      if (mask[i] == 0) {
        for(int k = 0; k <= (j?1:n); k++)
          dp[i+1][j || (k < n)] += dp[i][j];
      } else {
        int k = (mask[i]==2?1:0);
        if (j || k<=n)
          dp[i+1][j || (k < n)] += dp[i][j];
      }
    }
    return dp[62][1];
  };
  cout << DP(r+1)-DP(l) << endl;
  return 0;
}
0