結果

問題 No.911 ラッキーソート
ユーザー mamekinmamekin
提出日時 2019-11-09 20:34:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 117,488 KB
実行使用メモリ 4,844 KB
最終ジャッジ日時 2023-10-13 07:33:21
合計ジャッジ時間 10,197 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 2 ms
4,356 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 185 ms
4,624 KB
testcase_14 AC 189 ms
4,620 KB
testcase_15 AC 187 ms
4,716 KB
testcase_16 AC 195 ms
4,740 KB
testcase_17 AC 194 ms
4,608 KB
testcase_18 AC 197 ms
4,668 KB
testcase_19 AC 195 ms
4,584 KB
testcase_20 AC 193 ms
4,544 KB
testcase_21 AC 194 ms
4,588 KB
testcase_22 AC 195 ms
4,660 KB
testcase_23 AC 185 ms
4,348 KB
testcase_24 AC 169 ms
4,452 KB
testcase_25 AC 102 ms
4,352 KB
testcase_26 AC 83 ms
4,348 KB
testcase_27 AC 39 ms
4,348 KB
testcase_28 AC 20 ms
4,352 KB
testcase_29 AC 6 ms
4,352 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 1 ms
4,352 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,356 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 192 ms
4,664 KB
testcase_39 AC 188 ms
4,388 KB
testcase_40 AC 5 ms
4,352 KB
testcase_41 AC 190 ms
4,660 KB
testcase_42 AC 103 ms
4,356 KB
testcase_43 AC 189 ms
4,844 KB
testcase_44 AC 187 ms
4,740 KB
testcase_45 AC 194 ms
4,624 KB
testcase_46 AC 163 ms
4,560 KB
testcase_47 AC 187 ms
4,620 KB
testcase_48 AC 155 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

long long solve(const vector<long long>& a, long long x)
{
    if(x == -1)
        return 0;

    int n = a.size();
    vector<long long> dp = {1, 0};
    for(int i=62; i>=0; --i){
        bool up = false;
        bool down = false;
        for(int j=0; j<n-1; ++j){
            if((a[j] >> (i + 1)) != (a[j+1] >> (i + 1)))
                continue;
            if((a[j] & (1LL << i)) < (a[j+1] & (1LL << i)))
                up = true;
            else if((a[j] & (1LL << i)) > (a[j+1] & (1LL << i)))
                down = true;
        }

        vector<long long> nextDp(2, 0);
        if(!up){
            if(x & (1LL << i))
                nextDp[0] += dp[0];
            nextDp[1] += dp[1];
        }
        if(!down){
            if(x & (1LL << i)){
                nextDp[1] += dp[0] + dp[1];
            }
            else{
                nextDp[0] += dp[0];
                nextDp[1] += dp[1];
            }
        }
        dp = move(nextDp);
    }
    return dp[0] + dp[1];
}

int main()
{
    int n;
    long long l, r;
    cin >> n >> l >> r;
    vector<long long> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    long long ans = solve(a, r) - solve(a, l-1);
    cout << ans << endl;

    return 0;
}
0