結果

問題 No.911 ラッキーソート
ユーザー chocoruskchocorusk
提出日時 2019-10-18 22:11:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 2,280 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 109,184 KB
実行使用メモリ 5,200 KB
最終ジャッジ日時 2023-09-07 23:50:20
合計ジャッジ時間 7,321 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 138 ms
4,928 KB
testcase_14 AC 140 ms
4,980 KB
testcase_15 AC 139 ms
5,148 KB
testcase_16 AC 143 ms
4,880 KB
testcase_17 AC 142 ms
5,056 KB
testcase_18 AC 142 ms
4,892 KB
testcase_19 AC 140 ms
4,928 KB
testcase_20 AC 138 ms
4,920 KB
testcase_21 AC 142 ms
4,904 KB
testcase_22 AC 139 ms
4,944 KB
testcase_23 AC 129 ms
5,104 KB
testcase_24 AC 118 ms
4,700 KB
testcase_25 AC 75 ms
4,380 KB
testcase_26 AC 57 ms
4,380 KB
testcase_27 AC 28 ms
4,380 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 5 ms
4,388 KB
testcase_30 AC 3 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 143 ms
5,144 KB
testcase_39 AC 136 ms
4,804 KB
testcase_40 AC 5 ms
4,384 KB
testcase_41 AC 141 ms
4,908 KB
testcase_42 AC 89 ms
4,380 KB
testcase_43 AC 141 ms
4,876 KB
testcase_44 AC 130 ms
5,200 KB
testcase_45 AC 133 ms
4,880 KB
testcase_46 AC 131 ms
4,980 KB
testcase_47 AC 130 ms
4,996 KB
testcase_48 AC 127 ms
4,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int b[61];
ll solve(ll r){
    if(r<0) return 0;
    int nuo=1;
    for(int i=0; i<61; i++){
        if(b[i]==1) nuo=0;
    }
    ll dp[2][61]={};
    for(int i=0; i<61; i++){
        if((1ll<<i)>r) continue;
        if(b[i]!=0){
            bool dame=0;
            for(int j=i+1; j<61; j++){
                if(b[j]==1) dame=1;
            }
            if(dame) continue;
            if((1ll<<(i+1))>r) dp[0][i]=1;
            else dp[1][i]=1;
        }
    }
    for(int i=59; i>=0; i--){
        if(r&(1ll<<i)){
            if(b[i]!=0){
                dp[0][i]+=dp[0][i+1];
                dp[1][i]+=dp[1][i+1];
            }
            if(b[i]!=1){
                dp[1][i]+=dp[0][i+1]+dp[1][i+1];
            }
        }else{
            if(b[i]!=1){
                dp[0][i]+=dp[0][i+1];
                dp[1][i]+=dp[1][i+1];
            }
            if(b[i]!=0){
                dp[1][i]+=dp[1][i+1];
            }
        }
    }
    return dp[0][0]+dp[1][0]+nuo;
}
int main()
{
    int n;
    ll l, r;
    cin>>n>>l>>r;
    ll a[200020];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    fill(b, b+61, -1);
    for(int i=0; i<n-1; i++){
        for(int j=60; j>=0; j--){
            if(((a[i]>>j)&1ll)!=((a[i+1]>>j)&1ll)){
                if(((a[i]>>j)&1ll)<((a[i+1]>>j)&1ll)){
                    if(b[j]==1){
                        cout<<0<<endl;
                        return 0;
                    }
                    b[j]=0;
                }else{
                    if(b[j]==0){
                        cout<<0<<endl;
                        return 0;
                    }
                    b[j]=1;
                }
                break;
            }
        }
    }
    cout<<solve(r)-solve(l-1)<<endl;
    return 0;
}
0