結果

問題 No.911 ラッキーソート
ユーザー Noze
提出日時 2019-10-23 23:38:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 95,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 10:33:09
合計ジャッジ時間 5,743 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

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