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

        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 C - 増築王高橋君
User k3kaimu
Language D (DMD 2.060)
Score 30
Code Size 2602 Byte
Status
Exec Time 2041 ms
Memory 8848 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0_sample-01.txt, subtask0_sample-02.txt
Subtask1 30 / 30 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt
Subtask2 0 / 10 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Subtask3 0 / 15 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt
Subtask4 0 / 45 subtask0_sample-01.txt, subtask0_sample-02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt, subtask4_01.txt, subtask4_02.txt, subtask4_03.txt, subtask4_04.txt, subtask4_05.txt, subtask4_06.txt, subtask4_07.txt, subtask4_08.txt, subtask4_09.txt, subtask4_10.txt, subtask4_11.txt, subtask4_12.txt, subtask4_13.txt, subtask4_14.txt
Case Name Status Exec Time Memory
subtask0_sample-01.txt 119 ms 972 KB
subtask0_sample-02.txt 26 ms 980 KB
subtask1_01.txt 26 ms 984 KB
subtask1_02.txt 25 ms 976 KB
subtask1_03.txt 25 ms 1052 KB
subtask1_04.txt 26 ms 980 KB
subtask1_05.txt 30 ms 1096 KB
subtask1_06.txt 26 ms 980 KB
subtask1_07.txt 25 ms 1140 KB
subtask1_08.txt 31 ms 1100 KB
subtask1_09.txt 30 ms 1048 KB
subtask1_10.txt 37 ms 1056 KB
subtask1_11.txt 35 ms 1096 KB
subtask1_12.txt 25 ms 972 KB
subtask2_01.txt 25 ms 980 KB
subtask2_02.txt 161 ms 1104 KB
subtask2_03.txt 87 ms 1096 KB
subtask2_04.txt 34 ms 1016 KB
subtask2_05.txt 128 ms 1052 KB
subtask2_06.txt 2036 ms 1988 KB
subtask2_07.txt 2037 ms 1680 KB
subtask2_08.txt 1666 ms 1616 KB
subtask2_09.txt 2037 ms 1744 KB
subtask2_10.txt 2036 ms 1944 KB
subtask2_11.txt 2036 ms 1884 KB
subtask2_12.txt 2038 ms 1492 KB
subtask3_01.txt 79 ms 1100 KB
subtask3_02.txt 31 ms 1052 KB
subtask3_03.txt 2036 ms 1584 KB
subtask3_04.txt 2038 ms 8840 KB
subtask3_05.txt 78 ms 1864 KB
subtask3_06.txt 2037 ms 1736 KB
subtask3_07.txt 2038 ms 2760 KB
subtask3_08.txt 2039 ms 8084 KB
subtask3_09.txt 2039 ms 8848 KB
subtask3_10.txt 2038 ms 8796 KB
subtask3_11.txt 2039 ms 8732 KB
subtask3_12.txt 2038 ms 4944 KB
subtask4_01.txt 2038 ms 8836 KB
subtask4_02.txt 2036 ms 1168 KB
subtask4_03.txt 2038 ms 1744 KB
subtask4_04.txt 2039 ms 8792 KB
subtask4_05.txt 2037 ms 1224 KB
subtask4_06.txt 2036 ms 1096 KB
subtask4_07.txt 2035 ms 1176 KB
subtask4_08.txt 746 ms 1052 KB
subtask4_09.txt 2036 ms 7764 KB
subtask4_10.txt 2037 ms 1220 KB
subtask4_11.txt 2038 ms 8840 KB
subtask4_12.txt 2039 ms 8848 KB
subtask4_13.txt 2041 ms 8848 KB
subtask4_14.txt 2036 ms 1108 KB