結果

問題 No.911 ラッキーソート
ユーザー pekempey
提出日時 2019-10-18 23:36:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 171,132 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 19:57:03
合計ジャッジ時間 5,175 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define repr2(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N, L, R; cin >> N >> L >> R;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  ll dp[62][2][2] = {};
  dp[61][0][0] = 1;
  repr(i, 61) {
    bool can[2] = {};
    auto sorted = [&]() {
      rep(j, N-1) {
        if ((A[j] >> i) > (A[j + 1] >> i)) return false;
      }
      return true;
    };
    if (sorted()) {
      can[0] = true;
    }
    rep(j, N) A[j] ^= 1LL << i;
    if (sorted()) {
      can[1] = true;
    } else {
      rep(j, N) A[j] ^= 1LL << i;
    }
    rep(j, 2) rep(k, 2) {
      int x = L >> i & 1;
      int y = R >> i & 1;
      int l = j ? 0 : x;
      int r = k ? 1 : y;
      rep2(d, l, r + 1) if (can[d]) {
        dp[i][j || d > x][k || d < y] += dp[i + 1][j][k];
      }
    }
  }
  ll ans = 0;
  rep(j, 2) rep(k, 2) ans += dp[0][j][k];
  cout << ans << endl;
}
0