Submission #1415527
Source Code Expand
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
import std.concurrency;
void main() {
int N;
readf("%d\n", &N);
long[] xs = readln.split.to!(long[]);
int M; long K;
readf("%d %d\n", &M, &K);
int[] as = readln.split.to!(int[]).map!"a-2".array;
long[] ys = zip(xs[1..$], xs[0..$-1]).map!"a[0]-a[1]".array;
int[] id() {
return (N-1).iota.array.to!(int[]);
}
int[] mul(int[] us, int[] vs) {
return us.length.iota.map!(i => us[i]).map!(i => vs[i]).array;
}
int[] pow(int[] vs, long n) {
if (n==0) {
return id();
} else {
int[] res = pow(vs, n/2);
if (n%2 == 1) {
res = mul(res, vs);
}
return res;
}
}
int[] bs = pow(
as.fold!(
(vs, a) {
swap(vs[a], vs[a+1]);
return vs;
}
)(id()),
K
);
bs.map!(b => ys[b]).cumulativeFold!"a+b"(xs.front).array.pipe!(a => xs.front.to!long.only.array ~ a).each!writeln;
}
// ----------------------------------------------
void times(alias fun)(int n) {
// n.iota.each!(i => fun());
foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(int n) {
// return n.iota.map!(i => fun()).array;
T[] res = new T[n];
foreach(ref e; res) e = fun();
return res;
}
// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
template fold(fun...) if (fun.length >= 1) {
auto fold(R, S...)(R r, S seed) {
static if (S.length < 2) {
return reduce!fun(seed, r);
} else {
return reduce!fun(tuple(seed), r);
}
}
}
}
// cumulativeFold was added in D 2.072.0
static if (__VERSION__ < 2072) {
template cumulativeFold(fun...)
if (fun.length >= 1)
{
import std.meta : staticMap;
private alias binfuns = staticMap!(binaryFun, fun);
auto cumulativeFold(R)(R range)
if (isInputRange!(Unqual!R))
{
return cumulativeFoldImpl(range);
}
auto cumulativeFold(R, S)(R range, S seed)
if (isInputRange!(Unqual!R))
{
static if (fun.length == 1)
return cumulativeFoldImpl(range, seed);
else
return cumulativeFoldImpl(range, seed.expand);
}
private auto cumulativeFoldImpl(R, Args...)(R range, ref Args args)
{
import std.algorithm.internal : algoFormat;
static assert(Args.length == 0 || Args.length == fun.length,
algoFormat("Seed %s does not have the correct amount of fields (should be %s)",
Args.stringof, fun.length));
static if (args.length)
alias State = staticMap!(Unqual, Args);
else
alias State = staticMap!(ReduceSeedType!(ElementType!R), binfuns);
foreach (i, f; binfuns)
{
static assert(!__traits(compiles, f(args[i], e)) || __traits(compiles,
{ args[i] = f(args[i], e); }()),
algoFormat("Incompatible function/seed/element: %s/%s/%s",
fullyQualifiedName!f, Args[i].stringof, E.stringof));
}
static struct Result
{
private:
R source;
State state;
this(R range, ref Args args)
{
source = range;
if (source.empty)
return;
foreach (i, f; binfuns)
{
static if (args.length)
state[i] = f(args[i], source.front);
else
state[i] = source.front;
}
}
public:
@property bool empty()
{
return source.empty;
}
@property auto front()
{
assert(!empty, "Attempting to fetch the front of an empty cumulativeFold.");
static if (fun.length > 1)
{
import std.typecons : tuple;
return tuple(state);
}
else
{
return state[0];
}
}
void popFront()
{
assert(!empty, "Attempting to popFront an empty cumulativeFold.");
source.popFront;
if (source.empty)
return;
foreach (i, f; binfuns)
state[i] = f(state[i], source.front);
}
static if (isForwardRange!R)
{
@property auto save()
{
auto result = this;
result.source = source.save;
return result;
}
}
static if (hasLength!R)
{
@property size_t length()
{
return source.length;
}
}
}
return Result(range, args);
}
}
}
// minElement/maxElement was added in D 2.072.0
static if (__VERSION__ < 2072) {
auto minElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto minimum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b < minimum) {
element = a;
minimum = b;
}
}
return element;
}
auto maxElement(alias map, Range)(Range r)
if (isInputRange!Range && !isInfinite!Range)
{
alias mapFun = unaryFun!map;
auto element = r.front;
auto maximum = mapFun(element);
r.popFront;
foreach(a; r) {
auto b = mapFun(a);
if (b > maximum) {
element = a;
maximum = b;
}
}
return element;
}
}
Submission Info
Submission Time |
|
Task |
C - Rabbit Exercise |
User |
arkark |
Language |
D (DMD64 v2.070.1) |
Score |
0 |
Code Size |
6865 Byte |
Status |
WA |
Exec Time |
87 ms |
Memory |
16004 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt, 0_01.txt, 0_02.txt |
All |
0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
256 KB |
0_01.txt |
AC |
1 ms |
256 KB |
0_02.txt |
AC |
1 ms |
256 KB |
1_00.txt |
AC |
1 ms |
256 KB |
1_01.txt |
AC |
1 ms |
256 KB |
1_02.txt |
AC |
70 ms |
12292 KB |
1_03.txt |
WA |
87 ms |
16004 KB |
1_04.txt |
WA |
66 ms |
12628 KB |
1_05.txt |
WA |
4 ms |
1020 KB |
1_06.txt |
WA |
11 ms |
3068 KB |
1_07.txt |
WA |
7 ms |
1640 KB |
1_08.txt |
WA |
10 ms |
2956 KB |
1_09.txt |
WA |
10 ms |
2812 KB |
1_10.txt |
WA |
4 ms |
892 KB |
1_11.txt |
WA |
7 ms |
2556 KB |
1_12.txt |
WA |
2 ms |
380 KB |
1_13.txt |
WA |
12 ms |
3068 KB |
1_14.txt |
WA |
8 ms |
3020 KB |
1_15.txt |
WA |
20 ms |
4484 KB |
1_16.txt |
WA |
6 ms |
1404 KB |
1_17.txt |
WA |
47 ms |
10812 KB |
1_18.txt |
WA |
63 ms |
12392 KB |
1_19.txt |
WA |
76 ms |
15284 KB |
1_20.txt |
WA |
33 ms |
6796 KB |
1_21.txt |
WA |
34 ms |
9436 KB |
1_22.txt |
WA |
72 ms |
13364 KB |
1_23.txt |
WA |
72 ms |
11936 KB |
1_24.txt |
WA |
50 ms |
11000 KB |
1_25.txt |
AC |
69 ms |
14652 KB |