結果

問題 No.911 ラッキーソート
ユーザー snow39snow39
提出日時 2019-10-18 23:16:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,755 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 93,516 KB
実行使用メモリ 4,836 KB
最終ジャッジ日時 2023-09-08 02:18:03
合計ジャッジ時間 6,240 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 133 ms
4,836 KB
testcase_14 AC 137 ms
4,516 KB
testcase_15 AC 139 ms
4,516 KB
testcase_16 AC 138 ms
4,708 KB
testcase_17 AC 140 ms
4,692 KB
testcase_18 AC 136 ms
4,560 KB
testcase_19 AC 139 ms
4,800 KB
testcase_20 AC 138 ms
4,672 KB
testcase_21 AC 138 ms
4,628 KB
testcase_22 AC 136 ms
4,556 KB
testcase_23 AC 121 ms
4,384 KB
testcase_24 AC 115 ms
4,376 KB
testcase_25 AC 76 ms
4,376 KB
testcase_26 AC 57 ms
4,380 KB
testcase_27 AC 28 ms
4,380 KB
testcase_28 AC 15 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 140 ms
4,700 KB
testcase_39 AC 138 ms
4,384 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 139 ms
4,696 KB
testcase_42 AC 89 ms
4,380 KB
testcase_43 AC 136 ms
4,576 KB
testcase_44 AC 130 ms
4,612 KB
testcase_45 AC 134 ms
4,552 KB
testcase_46 AC 132 ms
4,720 KB
testcase_47 AC 130 ms
4,540 KB
testcase_48 AC 129 ms
4,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int rais[63];

ll nthbit(ll x,ll n){
    if(x>>n&1) return 1;
    else return 0;
}

ll dp[63][2][2];

int main(){
  int N;
  ll L,R;
  cin>>N>>L>>R;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  for(int i=0;i<N-1;i++){
      for(int j=60;j>=0;j--){
          if(nthbit(A[i],j)!=nthbit(A[i+1],j)){
              if(nthbit(A[i],j)){
                  if(rais[j]==-1){
                      cout<<0<<endl;
                      return 0;
                  }
                  rais[j]=1;
              }
              else{
                  if(rais[j]==1){
                      cout<<0<<endl;
                      return 0;
                  }
                  rais[j]=-1;
              }
              break;
          }
      }
  }

  dp[61][0][0]=1;
  for(ll i=61;i>0;i--){
      for(int j=0;j<2;j++) for(int k=0;k<2;k++){
          for(int l=0;l<2;l++){
              ll val=dp[i][j][k];
              int nj=j,nk=k;
              if(val==0) continue;

              if(j==0&&l==0&&nthbit(L,i-1)) continue;
              if(k==0&&l==1&&nthbit(R,i-1)==0) continue;
              if(rais[i-1]==1&&l==0) continue;
              if(rais[i-1]==-1&&l==1) continue;

              if(l==1&&nthbit(L,i-1)==0) nj=1;
              if(l==0&&nthbit(R,i-1)) nk=1;

              dp[i-1][nj][nk]+=val;
          }
      }
  }

  ll ans=0;
  for(int j=0;j<2;j++) for(int k=0;k<2;k++) ans+=dp[0][j][k];
  cout<<ans<<endl;

  return 0;
}
0