結果

問題 No.911 ラッキーソート
ユーザー HyadoHyado
提出日時 2019-10-19 13:22:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 2,595 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 170,076 KB
実行使用メモリ 4,864 KB
最終ジャッジ日時 2023-09-09 09:01:50
合計ジャッジ時間 8,696 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,504 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 209 ms
4,644 KB
testcase_14 AC 212 ms
4,684 KB
testcase_15 AC 208 ms
4,636 KB
testcase_16 AC 216 ms
4,860 KB
testcase_17 AC 216 ms
4,864 KB
testcase_18 AC 216 ms
4,616 KB
testcase_19 AC 216 ms
4,584 KB
testcase_20 AC 212 ms
4,532 KB
testcase_21 AC 210 ms
4,640 KB
testcase_22 AC 204 ms
4,740 KB
testcase_23 AC 198 ms
4,384 KB
testcase_24 AC 180 ms
4,428 KB
testcase_25 AC 109 ms
4,380 KB
testcase_26 AC 90 ms
4,380 KB
testcase_27 AC 42 ms
4,384 KB
testcase_28 AC 21 ms
4,376 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 214 ms
4,696 KB
testcase_39 AC 203 ms
4,636 KB
testcase_40 AC 6 ms
4,380 KB
testcase_41 AC 211 ms
4,568 KB
testcase_42 AC 108 ms
4,376 KB
testcase_43 AC 212 ms
4,688 KB
testcase_44 AC 129 ms
4,692 KB
testcase_45 AC 132 ms
4,644 KB
testcase_46 AC 131 ms
4,576 KB
testcase_47 AC 129 ms
4,616 KB
testcase_48 AC 125 ms
4,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
   T res = 1;
   for (; n; n >>= 1)
   {
      if (n & 1)
         res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);

ll two[61] = {};

ll solve(vector<ll> &v, ll r)
{
   if(r<0)return 0;

   ll n = siz(v), x = 60;

   vector<bool> ch(n, false);
   ll dp[65][2] = {};
   dp[61][0] = 1;
   ch[n - 1] = true;

   while (x >= 0)
   {
      ll y = two[x];
      ll ced = 0;
      bool f01 = 0, f10 = 0, st = (v[0] & y);
      rep(i, 0, n + 1)
      {
         if (0 < i && ch[i - 1])
         {
            if (ced == 1)
            {
               if (st == 1)
                  f10 = true;
               else
                  f01 = true;
            }
            if (i == n)
               break;
            st = (v[i] & y);
            ced = 0;
         }

         if (i > 0 && !ch[i - 1] && (y & v[i]) != (y & v[i - 1]))
         {
            ced++;
            if (ced == 2)
            {
               return 0;
            }
            ch[i - 1] = true;
         }
      }

      if (f10 && f01)
      {
         return 0;
      }
      else if (f10)
      {
         if(r & y)dp[x][0] = dp[x + 1][0];
      }
      else if (f01)
      {
         if (r & y)
            dp[x][1] = dp[x + 1][0];
         else
            dp[x][0] = dp[x + 1][0];
      }
      else
      {
         if (r & y)
         {
            dp[x][1] = dp[x + 1][0];
         }
         dp[x][0] = dp[x + 1][0];
         dp[x][1]+=dp[x+1][1];//
      }
      dp[x][1] += dp[x + 1][1];
      x--;
   }

   return dp[0][0] + dp[0][1];
}

signed main()
{
   two[0] = 1;
   rep(i, 1, 61) two[i] = two[i - 1] * 2;

   ll n, l, r;
   cin >> n >> l >> r;
   vector<ll> v(n);
   rep(i, 0, n) cin >> v[i];

   cout << solve(v, r) -solve(v, l - 1) << endl;
   //cout << solve(v, l - 1) << endl;

   return 0;
}
0