結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
leaf_1415
|
| 提出日時 | 2019-10-18 22:20:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 95 ms / 2,000 ms |
| コード長 | 1,400 bytes |
| コンパイル時間 | 1,084 ms |
| コンパイル使用メモリ | 57,048 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 17:13:08 |
| 合計ジャッジ時間 | 4,748 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long
using namespace std;
llint n, l, r;
llint a[200005];
bool up[65], down[35];
llint dp[65][2];
bool dfs(llint l, llint r, llint h)
{
int bd = 0;
for(int i = l; i < r; i++){
if(((a[i] >> h) & 1) < ((a[i+1] >> h) & 1)) up[h] = true, bd = i;
if(((a[i] >> h) & 1) > ((a[i+1] >> h) & 1)) down[h] = true, bd = i;
}
if(up[h] && down[h]) return false;
if(h > 0){
if(bd) dfs(l, bd, h-1), dfs(bd+1, r, h-1);
else dfs(l, r, h-1);
}
return true;
}
llint calc(llint x)
{
if(x < 0) return 0;
for(int i = 61; i >= 0; i--){
for(int j = 0; j < 2; j++){
dp[i][j] = 0;
}
}
dp[61][0] = 1;
for(int i = 61; i > 0; i--){
for(int j = 0; j < 2; j++){
for(int k = 0; k < 2; k++){
if(up[i-1] && k == 1) continue;
if(down[i-1] && k == 0) continue;
if(k == 1 && ((x&(1LL<<(i-1))) == 0) && j == 0) continue;
int nj = j;
if(k == 0 && ((x&(1LL<<(i-1))) != 0)) nj = 1;
dp[i-1][nj] += dp[i][j];
}
}
}
/*for(int i = 61; i >= 0; i--){
for(int j = 0; j < 2; j++){
cout << dp[i][j] << " ";
}
cout << endl;
}*/
return dp[0][0] + dp[0][1];
}
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> l >> r;
for(int i = 1; i <= n; i++) cin >> a[i];
if(!dfs(1, n, 60)){
cout << 0 << endl;
return 0;
}
cout << calc(r) - calc(l-1) << endl;
return 0;
}
leaf_1415