結果

問題 No.911 ラッキーソート
ユーザー tko919tko919
提出日時 2019-10-19 17:58:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 461 ms / 2,000 ms
コード長 1,828 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 165,744 KB
実行使用メモリ 114,684 KB
最終ジャッジ日時 2023-09-09 21:47:15
合計ジャッジ時間 12,529 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,796 KB
testcase_01 AC 2 ms
5,652 KB
testcase_02 AC 2 ms
5,628 KB
testcase_03 AC 2 ms
5,616 KB
testcase_04 AC 2 ms
5,668 KB
testcase_05 AC 2 ms
5,680 KB
testcase_06 AC 2 ms
5,808 KB
testcase_07 AC 2 ms
5,816 KB
testcase_08 AC 2 ms
5,552 KB
testcase_09 AC 2 ms
5,544 KB
testcase_10 AC 2 ms
5,516 KB
testcase_11 AC 2 ms
5,584 KB
testcase_12 AC 2 ms
5,468 KB
testcase_13 AC 319 ms
114,420 KB
testcase_14 AC 348 ms
114,512 KB
testcase_15 AC 331 ms
114,404 KB
testcase_16 AC 352 ms
114,488 KB
testcase_17 AC 374 ms
114,420 KB
testcase_18 AC 361 ms
114,428 KB
testcase_19 AC 359 ms
114,480 KB
testcase_20 AC 387 ms
114,532 KB
testcase_21 AC 417 ms
113,164 KB
testcase_22 AC 426 ms
110,976 KB
testcase_23 AC 405 ms
103,888 KB
testcase_24 AC 366 ms
94,360 KB
testcase_25 AC 227 ms
62,792 KB
testcase_26 AC 174 ms
48,516 KB
testcase_27 AC 88 ms
26,048 KB
testcase_28 AC 40 ms
15,896 KB
testcase_29 AC 8 ms
9,652 KB
testcase_30 AC 3 ms
6,176 KB
testcase_31 AC 2 ms
5,796 KB
testcase_32 AC 2 ms
5,540 KB
testcase_33 AC 2 ms
5,568 KB
testcase_34 AC 2 ms
5,528 KB
testcase_35 AC 2 ms
5,804 KB
testcase_36 AC 2 ms
5,540 KB
testcase_37 AC 2 ms
5,580 KB
testcase_38 AC 388 ms
114,684 KB
testcase_39 AC 455 ms
106,764 KB
testcase_40 AC 6 ms
9,544 KB
testcase_41 AC 461 ms
114,548 KB
testcase_42 AC 153 ms
75,144 KB
testcase_43 AC 318 ms
114,420 KB
testcase_44 AC 97 ms
114,484 KB
testcase_45 AC 98 ms
114,340 KB
testcase_46 AC 88 ms
114,372 KB
testcase_47 AC 95 ms
114,488 KB
testcase_48 AC 81 ms
110,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end

int n; ll a[200010],b[200010][70]={};
ll sum(ll x){
    if(x==-1)return 0;
    ll dp[70][2]={}; //dp[i][j]:=iビットまで j:x以下が確定している
    dp[63][0]=1;
    rrep(i,62,-1)rep(j,0,2)if(dp[i+1][j]){
        rep(k,0,2){
            int nj=j; bool can=1;
            if(!j&&k&&!(x>>i&1))continue;
            if((x>>i&1)&&!k)nj=1;
            rep(l,0,n-1){
                if(b[l][i+1]==b[l+1][i+1]){
                    if(k==0){
                        if((a[l]>>i&1)>(a[l+1]>>i&1)){
                            can=0; break;
                        }
                    }
                    else{
                        if((a[l]>>i&1)<(a[l+1]>>i&1)){
                            can=0; break;
                        }
                    }
                }
            }
            if(can)dp[i][nj]+=dp[i+1][j];
        }
    }
    return dp[0][0]+dp[0][1];
}

int main(){
    ll l,r; scanf("%d%lld%lld",&n,&l,&r);
    rep(i,0,n){
        scanf("%lld",&a[i]);
        rep(j,0,65)b[i][j]=(a[i]>>j);
    }
    bool f=1;
    rep(i,0,n-1)if(a[i]!=a[i+1])f=0;
    if(f&&n!=1){
        printf("0\n"); return 0;
    }
    printf("%lld\n",sum(r)-sum(l-1));
    return 0;
}
0