結果
| 問題 | No.911 ラッキーソート |
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2019-10-18 11:31:42 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 2,000 ms |
| コード長 | 2,404 bytes |
| 記録 | |
| コンパイル時間 | 2,146 ms |
| コンパイル使用メモリ | 106,240 KB |
| 実行使用メモリ | 47,476 KB |
| 最終ジャッジ日時 | 2024-06-25 14:01:59 |
| 合計ジャッジ時間 | 9,344 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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());
}
}
ei1333333