結果

問題 No.911 ラッキーソート
ユーザー pekempeypekempey
提出日時 2019-10-18 23:36:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 1,569 ms
コンパイル使用メモリ 168,700 KB
実行使用メモリ 4,820 KB
最終ジャッジ日時 2023-09-08 02:48:41
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 69 ms
4,532 KB
testcase_14 AC 71 ms
4,556 KB
testcase_15 AC 70 ms
4,540 KB
testcase_16 AC 72 ms
4,664 KB
testcase_17 AC 74 ms
4,556 KB
testcase_18 AC 74 ms
4,628 KB
testcase_19 AC 74 ms
4,540 KB
testcase_20 AC 74 ms
4,664 KB
testcase_21 AC 74 ms
4,676 KB
testcase_22 AC 73 ms
4,556 KB
testcase_23 AC 69 ms
4,408 KB
testcase_24 AC 63 ms
4,404 KB
testcase_25 AC 41 ms
4,376 KB
testcase_26 AC 31 ms
4,384 KB
testcase_27 AC 16 ms
4,376 KB
testcase_28 AC 9 ms
4,376 KB
testcase_29 AC 4 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 71 ms
4,600 KB
testcase_39 AC 72 ms
4,820 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 75 ms
4,564 KB
testcase_42 AC 49 ms
4,376 KB
testcase_43 AC 72 ms
4,568 KB
testcase_44 AC 54 ms
4,584 KB
testcase_45 AC 55 ms
4,672 KB
testcase_46 AC 55 ms
4,664 KB
testcase_47 AC 53 ms
4,664 KB
testcase_48 AC 52 ms
4,656 KB
権限があれば一括ダウンロードができます

ソースコード

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