結果
| 問題 |
No.911 ラッキーソート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-18 23:22:54 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,139 bytes |
| コンパイル時間 | 1,092 ms |
| コンパイル使用メモリ | 131,296 KB |
| 実行使用メモリ | 346,452 KB |
| 最終ジャッジ日時 | 2024-06-22 02:51:46 |
| 合計ジャッジ時間 | 5,544 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 35 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string, core.stdc.stdlib;
void main() {
auto s = readln.split.map!(to!long);
auto N = s[0].to!int;
auto L = s[1];
auto R = s[2];
auto A = readln.split.map!(to!long).array;
immutable int M = 61;
auto seq = new long[][][](M+1);
seq[0] ~= A.dup;
auto possible = new int[][](M+1);
void rec(int l, int r, int keta, int si) {
if (keta < 0) return;
auto B = A[l..r].map!(a => (a & (1L << keta)) > 0).array;
auto x = B.dup.uniq.array.length;
if (x > 2) {
writeln(0);
exit(0);
} else if (x == 2) {
possible[si-1] ~= B.front;
int cut = B.countUntil(!B.front).to!int;
seq[si] ~= A[l..l+cut].dup;
seq[si] ~= A[l+cut..r].dup;
rec(l, l+cut, keta-1, si+1);
rec(l+cut, r, keta-1, si+1);
} else {
possible[si-1] ~= 2;
seq[si] ~= A[l..r].dup;
rec(l, r, keta-1, si+1);
}
}
rec(0, N, M-1, 1);
long solve(long ub) {
auto dp = new long[][](M+1, 2);
dp[0][0] = 1;
foreach (i; 0..M) {
auto hoge = possible[i].dup.sort().uniq.array;
int[] nexts;
if (hoge.canFind(0) && hoge.canFind(1)) {
writeln(0);
exit(0);
} else if (hoge.canFind(0)) {
nexts ~= 0;
} else if (hoge.canFind(1)) {
nexts ~= 1;
} else {
nexts ~= [0, 1];
}
bool b = (ub & (1L << (M - i - 1))) > 0;
foreach (under; 0..2) {
foreach (next; nexts) {
if (!under && next && !b) continue;
dp[i+1][under||(next<b)] += dp[i][under];
}
}
}
return dp[M].sum;
}
auto ansR = solve(R);
auto ansL = L == 0 ? 0 : solve(L - 1);
writeln(ansR - ansL);
}