結果

問題 No.911 ラッキーソート
ユーザー chocoruskchocorusk
提出日時 2019-10-18 22:03:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,135 bytes
コンパイル時間 1,009 ms
コンパイル使用メモリ 110,056 KB
実行使用メモリ 5,096 KB
最終ジャッジ日時 2023-09-07 23:32:56
合計ジャッジ時間 7,396 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 133 ms
4,936 KB
testcase_14 AC 140 ms
4,988 KB
testcase_15 AC 135 ms
4,996 KB
testcase_16 AC 140 ms
4,932 KB
testcase_17 AC 138 ms
4,996 KB
testcase_18 AC 142 ms
5,096 KB
testcase_19 AC 141 ms
5,036 KB
testcase_20 AC 138 ms
4,944 KB
testcase_21 AC 141 ms
4,864 KB
testcase_22 AC 136 ms
4,852 KB
testcase_23 AC 128 ms
4,776 KB
testcase_24 AC 116 ms
4,648 KB
testcase_25 AC 74 ms
4,376 KB
testcase_26 AC 55 ms
4,376 KB
testcase_27 AC 27 ms
4,376 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 143 ms
4,864 KB
testcase_39 AC 136 ms
4,936 KB
testcase_40 WA -
testcase_41 AC 139 ms
4,992 KB
testcase_42 WA -
testcase_43 AC 137 ms
4,940 KB
testcase_44 AC 128 ms
5,048 KB
testcase_45 AC 131 ms
4,864 KB
testcase_46 AC 128 ms
4,884 KB
testcase_47 AC 128 ms
4,952 KB
testcase_48 AC 127 ms
4,932 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){
            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