結果

問題 No.911 ラッキーソート
ユーザー MayimgMayimg
提出日時 2019-10-20 15:19:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,320 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 200,804 KB
実行使用メモリ 4,756 KB
最終ジャッジ日時 2023-09-15 14:37:25
合計ジャッジ時間 5,768 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 58 ms
4,556 KB
testcase_16 WA -
testcase_17 AC 59 ms
4,636 KB
testcase_18 WA -
testcase_19 AC 59 ms
4,704 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 59 ms
4,380 KB
testcase_24 WA -
testcase_25 AC 35 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 1 ms
4,380 KB
testcase_34 WA -
testcase_35 AC 2 ms
4,380 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 60 ms
4,668 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 56 ms
4,676 KB
testcase_45 AC 58 ms
4,696 KB
testcase_46 AC 58 ms
4,736 KB
testcase_47 AC 57 ms
4,620 KB
testcase_48 AC 59 ms
4,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 62;
int mark[N];
long long calc (int lim, int cur, int f) {
  if (cur < 0) return 1;
  long long res = 0;
  if (mark[cur] == 0) {
    if (lim & (1LL << cur)) {
      res += 1LL << (cur - f);
    }
    res += calc (lim, cur - 1, f);
  }
  if (mark[cur] == 1) {
    f--;
    if (lim & (1LL << cur)) {
      res += 1LL << (cur - f);
    } else {
      res += calc (lim, cur - 1, f);
    }
  }
  if (mark[cur] == 2) {
    f--;
    if (lim & (1LL << cur)) {
      res += calc (lim, cur - 1, f);
    }
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, l, r;
  cin >> n >> l >> r;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i + 1 < n; i++) {
    for (int j = N - 1; j >= 0; j--) {
      if ((a[i] & (1LL << j)) == 0 && (a[i + 1] & (1LL << j))) {
        mark[j] |= 1;
        break;
      }
      if ((a[i] & (1LL << j)) && ((a[i + 1] & (1LL << j)) == 0)) {
        mark[j] |= 2;
        break;
      }
    }
  }
  int fx = 0;
  for (int i = 0; i < N; i++) {
    if (mark[i] == 3) {
      cout << 0 << '\n';
      return 0;
    }
    if (mark[i]) fx++;
  }
  cout << calc(r, N - 1, fx) - (l ? calc(l - 1, N - 1, fx) : 0) << '\n';
  return 0;
}
0