Contest Duration: ~ (local time) (90 minutes) Back to Home

Submission #159153

Source Code Expand

Copy
```import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.math;
import std.exception;
import std.bigint;

version = C;

}

}

void main()
{
version(A)
{
uint[][] tiles;
foreach(i; 0 .. 4)

writeln(probA(tiles));
}

version(B)
{
uint[] bs;

if(auto r = probB(bs))
writefln("%(%s\n%)", r);
else
writeln("-1");
}

version(C)
{
uint[][] values;

writeln(probC(k, values.map!"cast(uint[2])[a[0], a[1]]"().array()));
}
}

version(A)
string probA(uint[][] tiles)
{
enum gameO = "GAMEOVER";
enum conti = "CONTINUE";

foreach(i; 0 .. 4){
foreach(j; 1 .. 4){
if(tiles[i][j] == tiles[i][j-1])
return conti;

if(tiles[j][i] == tiles[j-1][i])
return conti;
}
}

return gameO;
}

version(A)
unittest {
assert(probA([[2, 8, 2, 2],
[32, 2, 8, 8],
[4, 64, 2, 128],
[2, 8, 4, 2]]) == "CONTINUE");

assert(probA([[2, 4, 16, 4],
[8, 32, 128, 8],
[2, 64, 16, 2],
[32, 4, 32, 4]]) == "GAMEOVER");

assert(probA([[2, 4, 2, 4],
[4, 2, 4, 2],
[2, 4, 2, 4],
[4, 2, 4, 2]]) == "GAMEOVER");
}

version(B)
uint[] probB(uint[] bs)
{
uint[] dst = [0];

foreach(i, e; bs)
dst ~= dst[i] ^ e;

if(dst[0] == dst[\$-1])
return dst[0 .. \$-1];
else
return null;
}

version(B)
unittest{
assert(probB([1, 1]) == [0, 1]);
assert(probB([1, 4, 1]) is null);
assert(probB([1, 2, 3]) == [0, 1, 3]);
}

version(C)
ulong probC(uint k, uint[2][] value)
{
ulong sum;

foreach(_; 0 .. k){
value.sort!"a[0] < b[0]"();

sum += value[0][0];
value[0][0] += value[0][1];
}

return sum;
}

version(C)
unittest
{
assert(probC(4, [[10, 3], [12, 4], [15, 5]]) == 50);
assert(probC(8, [[1, 1], [10, 1], [100, 1], [1000, 1]]));
}
```

#### Submission Info

Submission Time 2014-04-12 21:49:29+0900 C - 増築王高橋君 k3kaimu D (DMD 2.060) 30 2602 Byte TLE 2041 ms 8848 KB

#### Test Cases

Set Name Score / Max Score Test Cases
Case Name Status Exec Time Memory