結果

問題 No.911 ラッキーソート
ユーザー koyoprokoyopro
提出日時 2020-03-25 22:59:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 2,136 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 145,640 KB
実行使用メモリ 5,124 KB
最終ジャッジ日時 2023-08-30 11:51:04
合計ジャッジ時間 9,551 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 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 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 52 ms
4,932 KB
testcase_14 AC 53 ms
5,072 KB
testcase_15 AC 54 ms
4,940 KB
testcase_16 AC 55 ms
4,936 KB
testcase_17 AC 54 ms
4,952 KB
testcase_18 AC 55 ms
4,940 KB
testcase_19 AC 54 ms
4,932 KB
testcase_20 AC 55 ms
4,908 KB
testcase_21 AC 57 ms
4,904 KB
testcase_22 AC 57 ms
4,900 KB
testcase_23 AC 53 ms
4,780 KB
testcase_24 AC 49 ms
4,912 KB
testcase_25 AC 33 ms
4,376 KB
testcase_26 AC 24 ms
4,380 KB
testcase_27 AC 13 ms
4,376 KB
testcase_28 AC 7 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 54 ms
4,956 KB
testcase_39 AC 55 ms
4,820 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 55 ms
5,124 KB
testcase_42 AC 37 ms
4,488 KB
testcase_43 AC 54 ms
5,012 KB
testcase_44 AC 41 ms
4,944 KB
testcase_45 AC 44 ms
4,964 KB
testcase_46 AC 42 ms
4,944 KB
testcase_47 AC 43 ms
5,020 KB
testcase_48 AC 42 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,L,R;
int X[66],A[SIZE];

bool update() {
    REP(i,66)X[i]=-1;
    REP(i,N-1) {
        bitset<62> a(A[i]), b(A[i+1]);
        RREP(j,61) {
            if (a[j]<b[j]) {
                if (X[j]==1)
                    return false;
                X[j]=0;
                break;
            }
            if (a[j]>b[j]) {
                if (X[j]==0)
                    return false;
                X[j]=1;
                break;
            }
        }
    }
    return true;
}

// 桁DP(LorR/上からi桁目まで/未満フラグ → xの種類数
int DP[2][66][2];

void dp(int lr, int ma) {
    DP[lr][61][0]=1;
    DP[lr][61][1]=0;
    RREP(i,61) {
        REP(j,2) {
            int n = j ? 1 : (ma>>i & 1);
            REP(k,n+1) {
                if (X[i]==-1) {
                    DP[lr][i][j || k<n] += DP[lr][i+1][j];
                }
                else if (X[i]==k) {
                    DP[lr][i][j || k<n] += DP[lr][i+1][j];
                }
            }
        }
    }
}

void solve() {
    cin>>N>>L>>R;
    REP(i,N)cin>>A[i];
    if (!update()) {
        cout << 0 << endl;
        return;
    }
    // 桁DP
    if (L) dp(0,L-1);
    dp(1,R);
    int ans = DP[1][0][1]+DP[1][0][0] - (DP[0][0][1]+DP[0][0][0]);
    cout << ans << endl;
}
0