Submission #159197


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;
 
T[] readlnSome(T)(){
    return array(readln().split().map!(a => to!T(a))());
}
 
 
T readlnOne(T)(){
    return to!T(readln().split()[0]);
}
 
 
void main()
{
  version(A)
  {
    uint[][] tiles;
    foreach(i; 0 .. 4)
        tiles ~= readlnSome!uint()[0 .. 4];

    writeln(probA(tiles));
  }

  version(B)
  {
    uint[] bs;
    foreach(i; 0 .. readlnOne!uint())
        bs ~= readlnOne!uint();

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

  version(C)
  {
    uint k = readlnOne!uint();
    uint[][] values;
    foreach(i; 0 .. readlnOne!uint())
        values ~= readlnSome!uint()[0 .. 2];

    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]"();

        while(value[0][0] <= value[1][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
Task A - DEAD END
User k3kaimu
Language D (DMD 2.060)
Score 0
Code Size 2665 Byte
Status
Exec Time 80 ms
Memory 924 KB

Test Cases

Set Name Score / Max Score Test Cases
All 0 / 100 hand_1.txt, hand_2.txt, random_1.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_2.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_3.txt, random_30.txt, random_4.txt, random_5.txt, random_6.txt, random_7.txt, random_8.txt, random_9.txt
Case Name Status Exec Time Memory
hand_1.txt 21 ms 912 KB
hand_2.txt 22 ms 916 KB
random_1.txt 22 ms 916 KB
random_10.txt 22 ms 912 KB
random_11.txt 22 ms 800 KB
random_12.txt 20 ms 912 KB
random_13.txt 24 ms 792 KB
random_14.txt 21 ms 924 KB
random_15.txt 22 ms 924 KB
random_16.txt 22 ms 804 KB
random_17.txt 22 ms 924 KB
random_18.txt 22 ms 924 KB
random_19.txt 22 ms 848 KB
random_2.txt 24 ms 912 KB
random_20.txt 26 ms 844 KB
random_21.txt 21 ms 916 KB
random_22.txt 21 ms 924 KB
random_23.txt 22 ms 924 KB
random_24.txt 24 ms 924 KB
random_25.txt 23 ms 792 KB
random_26.txt 23 ms 924 KB
random_27.txt 23 ms 792 KB
random_28.txt 21 ms 924 KB
random_29.txt 21 ms 924 KB
random_3.txt 21 ms 916 KB
random_30.txt 22 ms 920 KB
random_4.txt 22 ms 916 KB
random_5.txt 22 ms 920 KB
random_6.txt 23 ms 788 KB
random_7.txt 22 ms 848 KB
random_8.txt 21 ms 920 KB
random_9.txt 21 ms 924 KB
sample_1.txt 80 ms 792 KB
sample_2.txt 22 ms 916 KB
sample_3.txt 21 ms 916 KB