Submission #159187


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[0][1]){
            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 0
Code Size 2665 Byte
Status
Exec Time 2035 ms
Memory 8548 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0_sample-01.txt, subtask0_sample-02.txt
Subtask1 0 / 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 21 ms 728 KB
subtask0_sample-02.txt 20 ms 804 KB
subtask1_01.txt 20 ms 752 KB
subtask1_02.txt 20 ms 920 KB
subtask1_03.txt 20 ms 808 KB
subtask1_04.txt 22 ms 832 KB
subtask1_05.txt 24 ms 800 KB
subtask1_06.txt 20 ms 796 KB
subtask1_07.txt 21 ms 796 KB
subtask1_08.txt 25 ms 800 KB
subtask1_09.txt 24 ms 804 KB
subtask1_10.txt 30 ms 928 KB
subtask1_11.txt 29 ms 932 KB
subtask1_12.txt 20 ms 928 KB
subtask2_01.txt 20 ms 928 KB
subtask2_02.txt 164 ms 804 KB
subtask2_03.txt 69 ms 916 KB
subtask2_04.txt 28 ms 928 KB
subtask2_05.txt 103 ms 800 KB
subtask2_06.txt 1807 ms 1572 KB
subtask2_07.txt 1955 ms 1320 KB
subtask2_08.txt 1475 ms 1432 KB
subtask2_09.txt 2029 ms 1572 KB
subtask2_10.txt 2035 ms 1704 KB
subtask2_11.txt 2029 ms 1700 KB
subtask2_12.txt 2030 ms 1316 KB
subtask3_01.txt 71 ms 928 KB
subtask3_02.txt 26 ms 932 KB
subtask3_03.txt 1928 ms 1436 KB
subtask3_04.txt 2030 ms 8544 KB
subtask3_05.txt 70 ms 1576 KB
subtask3_06.txt 2029 ms 1448 KB
subtask3_07.txt 2029 ms 2468 KB
subtask3_08.txt 2030 ms 7904 KB
subtask3_09.txt 2030 ms 8548 KB
subtask3_10.txt 2030 ms 8548 KB
subtask3_11.txt 2030 ms 8536 KB
subtask3_12.txt 2029 ms 4632 KB
subtask4_01.txt 2030 ms 8548 KB
subtask4_02.txt 2028 ms 932 KB
subtask4_03.txt 2029 ms 1440 KB
subtask4_04.txt 2030 ms 8544 KB
subtask4_05.txt 2028 ms 920 KB
subtask4_06.txt 2029 ms 936 KB
subtask4_07.txt 2029 ms 932 KB
subtask4_08.txt 651 ms 924 KB
subtask4_09.txt 2030 ms 7520 KB
subtask4_10.txt 2029 ms 988 KB
subtask4_11.txt 2029 ms 8548 KB
subtask4_12.txt 2030 ms 8540 KB
subtask4_13.txt 2030 ms 8548 KB
subtask4_14.txt 2028 ms 924 KB