結果

問題 No.911 ラッキーソート
ユーザー ei1333333ei1333333
提出日時 2019-10-18 11:31:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 2,404 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 65,336 KB
実行使用メモリ 53,908 KB
最終ジャッジ日時 2023-09-07 20:16:22
合計ジャッジ時間 14,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
18,816 KB
testcase_01 AC 61 ms
22,780 KB
testcase_02 AC 60 ms
18,652 KB
testcase_03 AC 61 ms
20,784 KB
testcase_04 AC 62 ms
20,796 KB
testcase_05 AC 62 ms
20,696 KB
testcase_06 AC 61 ms
20,772 KB
testcase_07 AC 61 ms
20,780 KB
testcase_08 AC 60 ms
20,800 KB
testcase_09 AC 63 ms
18,660 KB
testcase_10 AC 61 ms
18,680 KB
testcase_11 AC 61 ms
22,736 KB
testcase_12 AC 61 ms
20,772 KB
testcase_13 AC 218 ms
49,704 KB
testcase_14 AC 223 ms
49,944 KB
testcase_15 AC 218 ms
51,696 KB
testcase_16 AC 225 ms
49,952 KB
testcase_17 AC 227 ms
50,012 KB
testcase_18 AC 225 ms
52,028 KB
testcase_19 AC 226 ms
47,764 KB
testcase_20 AC 227 ms
51,708 KB
testcase_21 AC 226 ms
49,764 KB
testcase_22 AC 222 ms
45,456 KB
testcase_23 AC 215 ms
45,912 KB
testcase_24 AC 206 ms
49,972 KB
testcase_25 AC 153 ms
41,164 KB
testcase_26 AC 136 ms
38,956 KB
testcase_27 AC 100 ms
28,372 KB
testcase_28 AC 83 ms
22,300 KB
testcase_29 AC 73 ms
21,456 KB
testcase_30 AC 70 ms
20,916 KB
testcase_31 AC 63 ms
22,772 KB
testcase_32 AC 61 ms
22,756 KB
testcase_33 AC 63 ms
20,712 KB
testcase_34 AC 62 ms
20,824 KB
testcase_35 AC 69 ms
22,764 KB
testcase_36 AC 63 ms
22,804 KB
testcase_37 AC 61 ms
20,780 KB
testcase_38 AC 222 ms
52,040 KB
testcase_39 AC 221 ms
47,968 KB
testcase_40 AC 73 ms
25,476 KB
testcase_41 AC 227 ms
51,784 KB
testcase_42 AC 170 ms
43,216 KB
testcase_43 AC 221 ms
53,908 KB
testcase_44 AC 180 ms
49,632 KB
testcase_45 AC 183 ms
50,000 KB
testcase_46 AC 182 ms
51,928 KB
testcase_47 AC 180 ms
49,632 KB
testcase_48 AC 170 ms
45,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;

class Program
{
  Scanner cin;

  int N;
  long L, R;
  long[] A;

  int[] ok;


  long T;
  long[,] dp;

  long rec(int idx, int high)
  {
    if(idx == -1)
    {
      return 1;
    }
    if(dp[idx, high] != -1)
    {
      return dp[idx, high];
    }
    long ret = 0;
    for (int i = 0; i <= (high == 1 ? ((T >> idx) & 1) : 1); i++)
    {

      if (((ok[idx] >> i) & 1) == 0)
      {
        continue;
      }
      ret += rec(idx - 1, high & (((T >> idx) & 1) == i ? 1 : 0));
    }
    dp[idx, high] = ret;
    return ret;
  }

  long beet(long S)
  {
    if (S < 0) return 0;
    dp = new long[61, 2];
    for (int i = 0; i < 61; i++)
    {
      for (int j = 0; j < 2; j++)
      {
        dp[i, j] = -1;
      }
    }
    T = S;
    return rec(60, 1);
  }

  void myon()
  {
    cin = new Scanner();

    N = cin.nextInt();
    L = cin.nextLong();
    R = cin.nextLong();

    A = new long[N];
    for(int i = 0; i < N; i++)
    {
      A[i] = cin.nextLong();
    }


    ok = new int[61];
    long mask = 0, mask2 = 0;
    for (int i = 60; i >= 0; i--)
    {
      mask2 |= 1L << i;

      for (int j = 0; j < 2; j++)
      {
        long next = mask | ((long)j << i);
        long pre = -1;

        for (int k = 0; k < N; k++)
        {
          long cur = (next ^ A[k]) & mask2;
          if (cur < pre)
          {
            pre = -1;
            break;
          }
          pre = cur;
        }
        if (pre != -1)
        {
          ok[i] |= 1 << j;
        }
      }

      if (((ok[i] >> 0) & 1) == 0)
      {
        mask |= 1L << i;
      }
    }
    Console.WriteLine(beet(R) - beet(L - 1));
  }

  static void Main(string[] args)
  {
    new Program().myon();
  }
}

class Scanner
{
  string[] s;
  int i;
  readonly char[] cs = new char[] { ' ' };

  public Scanner()
  {
    s = new string[0];
    i = 0;
  }

  public string next()
  {
    if (i < s.Length) return s[i++];
    string st = Console.ReadLine();
    while (st == "") st = Console.ReadLine();
    s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
    if (s.Length == 0) return next();
    i = 0;
    return s[i++];
  }

  public string nextLine()
  {
    return Console.ReadLine();
  }

  public int nextInt()
  {
    return int.Parse(next());
  }

  public long nextLong()
  {
    return long.Parse(next());
  }

  public double nextDouble()
  {
    return double.Parse(next());
  }
}
0