結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-20 15:14:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,298 bytes |
| コンパイル時間 | 3,203 ms |
| コンパイル使用メモリ | 194,128 KB |
| 最終ジャッジ日時 | 2025-01-08 00:05:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 29 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int N = 62;
int mark[N];
int fr = 0;
long long calc (int lim, int cur, int f) {
if (cur < 0) return 1;
long long res = 0;
if (mark[cur] == 0) {
f--;
if (lim & (1LL << cur)) {
res += 1LL << f;
}
res += calc (lim, cur - 1, f);
}
if (mark[cur] == 1) {
if (lim & (1LL << cur)) {
res += 1LL << f;
} else {
res += calc (lim, cur - 1, f);
}
}
if (mark[cur] == 2) {
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;
}
}
}
for (int i = 0; i < N; i++) {
if (mark[i] == 3) {
cout << 0 << '\n';
return 0;
}
if (mark[i] == 0) fr++;
}
cout << calc(r, N - 1, fr) - (l ? calc(l - 1, N - 1, fr) : 0) << '\n';
return 0;
}