結果

問題 No.911 ラッキーソート
ユーザー 0w10w1
提出日時 2019-11-28 23:28:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 3,732 ms
コンパイル使用メモリ 205,468 KB
実行使用メモリ 5,244 KB
最終ジャッジ日時 2023-08-12 09:49:50
合計ジャッジ時間 11,001 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 60 ms
4,672 KB
testcase_14 AC 62 ms
4,896 KB
testcase_15 AC 63 ms
4,868 KB
testcase_16 AC 64 ms
4,664 KB
testcase_17 AC 63 ms
4,808 KB
testcase_18 AC 64 ms
4,608 KB
testcase_19 AC 63 ms
4,560 KB
testcase_20 AC 66 ms
4,564 KB
testcase_21 AC 69 ms
4,676 KB
testcase_22 AC 70 ms
4,612 KB
testcase_23 AC 64 ms
4,384 KB
testcase_24 AC 59 ms
4,468 KB
testcase_25 AC 40 ms
4,380 KB
testcase_26 AC 28 ms
4,380 KB
testcase_27 AC 15 ms
4,380 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 63 ms
5,244 KB
testcase_39 AC 68 ms
4,892 KB
testcase_40 AC 3 ms
4,384 KB
testcase_41 AC 65 ms
4,680 KB
testcase_42 AC 44 ms
4,384 KB
testcase_43 AC 61 ms
4,712 KB
testcase_44 AC 42 ms
4,712 KB
testcase_45 AC 46 ms
4,768 KB
testcase_46 AC 41 ms
4,564 KB
testcase_47 AC 43 ms
4,628 KB
testcase_48 AC 43 ms
4,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N;
  int64_t L, R;
  cin >> N >> L >> R;

  vector<int64_t> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  auto calc = [&](int64_t ub, bool inc) -> int64_t {
    vector<int> must(61, -1);
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 60; ~j; --j) {
        int x = A[i] >> j & 1;
        int y = A[i + 1] >> j & 1;
        if (x == y) continue;
        if (must[60 - j] == -1) must[60 - j] = y < x;
        if (must[60 - j] != (y < x)) return 0;
        break;
      }
    }
    vector<vector<int64_t>> dp(62, vector<int64_t>(2));
    dp[0][0] = 1;
    for (int i = 0; i < 61; ++i) {
      vector<int> choices;
      if (must[i] == -1) choices = { 0, 1 };
      else choices = { must[i] };
      for (int l = 0; l < 2; ++l) {
        int v = ub >> 60 - i & 1;
        for (int d : choices) {
          if (!l && v < d) continue;
          dp[i + 1][l | d < v] += dp[i][l];
        }
      }
    }
    int64_t res = dp[61][1];
    if (inc) res += dp[61][0];
    return res;
  };

  int64_t ans = calc(R, true) - calc(L, false);
  cout << ans << endl;

  return 0;
}
0