結果

問題 No.911 ラッキーソート
ユーザー ChanyuhChanyuh
提出日時 2020-02-03 08:56:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 2,737 bytes
コンパイル時間 958 ms
コンパイル使用メモリ 111,516 KB
実行使用メモリ 14,596 KB
最終ジャッジ日時 2023-10-19 01:40:44
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 212 ms
14,596 KB
testcase_14 AC 215 ms
14,596 KB
testcase_15 AC 207 ms
14,596 KB
testcase_16 AC 215 ms
14,596 KB
testcase_17 AC 212 ms
14,592 KB
testcase_18 AC 211 ms
14,588 KB
testcase_19 AC 207 ms
14,576 KB
testcase_20 AC 204 ms
14,540 KB
testcase_21 AC 187 ms
14,384 KB
testcase_22 AC 175 ms
14,192 KB
testcase_23 AC 168 ms
13,496 KB
testcase_24 AC 146 ms
12,572 KB
testcase_25 AC 84 ms
9,400 KB
testcase_26 AC 71 ms
7,920 KB
testcase_27 AC 31 ms
5,728 KB
testcase_28 AC 15 ms
4,664 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 2 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 207 ms
14,596 KB
testcase_39 AC 169 ms
13,780 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 196 ms
14,528 KB
testcase_42 AC 112 ms
10,592 KB
testcase_43 AC 218 ms
14,596 KB
testcase_44 AC 40 ms
5,216 KB
testcase_45 AC 40 ms
5,216 KB
testcase_46 AC 40 ms
5,216 KB
testcase_47 AC 40 ms
5,212 KB
testcase_48 AC 38 ms
5,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,x[62];
ll L,R,a[200010],dp[62][2][2];
bool l[62],r[62];

ll rec(int k,int flagL,int flagR){
  if(k==-1) return 1;
  if(dp[k][flagL][flagR]!=-1) return dp[k][flagL][flagR];
  ll res=0;
  // 1
  if(x[k]!=0 && (flagR || r[k]==1)) res+=rec(k-1,flagL||(l[k]==0),flagR);
  // 0
  if(x[k]!=1 && (flagL || l[k]==0)) res+=rec(k-1,flagL,flagR||(r[k]==1));
  dp[k][flagL][flagR]=res;
  //cout << k << " " << flagL << " " << flagR << " " << res << endl;
  return res;
}

void solve(){
  cin >> n >> L >> R;
  rep(k,62){
    l[k]=(L & (1ll << k));
    r[k]=(R & (1ll << k));
    //cout << l[k] << " " << r[k] << endl;
    rep(flagL,2){
      rep(flagR,2){
        dp[k][flagL][flagR]=-1;
      }
    }
  }
  rep(i,n){
    cin >> a[i];
  }
  per(k,62){
    x[k]=-1;
  }

  set<int> se{0,n};
  per(k,62){
    bool first,changed=false;
    auto idx=se.begin();
    vector<int> v={};
    //cout << k << endl;
    rep(i,n){
      bool b=(a[i]&(1ll << k));
      //cout << b << " ";
      if (*idx==i) {
        first=b;
        idx++;
        changed=false;
        continue;
      }
      bool pre_b=(a[i-1]&(1ll << k));
      if (pre_b!=b){
        v.push_back(i);
        if(changed) {
          cout << 0 << endl;
          return;
        }
        else{
          changed=true;
          int s=pre_b;
          if(x[k]==-1 || x[k]==s){
            x[k]=s;
          }
          else {
            cout << 0 << endl;
            return;
          }
        }
      }
    }
    for(int v_:v){
      se.insert(v_);
      //cout << v_ << " ";
    }
    //cout << "" << endl;
  }
  per(i,62){
    //cout << x[i] << " ";
  }
  //cout << "" << endl;
  cout << rec(61,0,0) << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0