結果

問題 No.911 ラッキーソート
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-10-18 21:58:57
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,419 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 106,292 KB
実行使用メモリ 14,644 KB
最終ジャッジ日時 2023-09-04 03:03:57
合計ジャッジ時間 7,413 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 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 64 ms
13,632 KB
testcase_14 AC 64 ms
14,624 KB
testcase_15 AC 62 ms
12,700 KB
testcase_16 AC 65 ms
13,884 KB
testcase_17 AC 65 ms
14,644 KB
testcase_18 AC 65 ms
12,188 KB
testcase_19 AC 63 ms
13,716 KB
testcase_20 AC 63 ms
13,148 KB
testcase_21 AC 64 ms
14,100 KB
testcase_22 AC 62 ms
13,144 KB
testcase_23 AC 58 ms
13,584 KB
testcase_24 AC 52 ms
10,520 KB
testcase_25 AC 34 ms
9,164 KB
testcase_26 AC 26 ms
6,416 KB
testcase_27 AC 13 ms
5,616 KB
testcase_28 AC 8 ms
5,296 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 65 ms
12,152 KB
testcase_39 AC 60 ms
12,440 KB
testcase_40 AC 3 ms
4,380 KB
testcase_41 AC 63 ms
12,728 KB
testcase_42 AC 41 ms
10,004 KB
testcase_43 AC 65 ms
14,248 KB
testcase_44 AC 63 ms
11,900 KB
testcase_45 AC 65 ms
13,024 KB
testcase_46 AC 62 ms
13,648 KB
testcase_47 AC 63 ms
14,620 KB
testcase_48 AC 60 ms
14,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum E = 61;

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

int[] con;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      L = readLong();
      R = readLong();
      A = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      
      con = new int[E];
      foreach (i; 0 .. N - 1) {
        const e = bsr(A[i] ^ A[i + 1]);
        if ((A[i] >> e) & 1) {
          con[e] |= 2;
        } else {
          con[e] |= 1;
        }
      }
      debug {
        writeln("con = ", con);
      }
      
      auto dp = new long[][][](E + 1, 2, 2);
      dp[E][0][0] = 1;
      foreach_reverse (e; 0 .. E) {
        foreach (s; 0 .. 2) foreach (t; 0 .. 2) {
          foreach (x; 0 .. 2) {
            if (s || ((L >> e) & 1) <= x) {
              if (t || (x <= ((R >> e) & 1))) {
                if (!((con[e] >> (x ^ 1)) & 1)) {
                  int ss = s, tt = t;
                  if (((L >> e) & 1) < x) ss = 1;
                  if (x < ((R >> e) & 1)) tt = 1;
                  dp[e][ss][tt] += dp[e + 1][s][t];
                }
              }
            }
          }
        }
      }
      long ans;
      foreach (s; 0 .. 2) foreach (t; 0 .. 2) {
        ans += dp[0][s][t];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
0