Submission #159263


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 C - 増築王高橋君
User k3kaimu
Language D (DMD 2.060)
Score 0
Code Size 2664 Byte
Status
Exec Time 2034 ms
Memory 8552 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 23 ms 920 KB
subtask0_sample-02.txt 22 ms 920 KB
subtask1_01.txt 23 ms 920 KB
subtask1_02.txt 22 ms 920 KB
subtask1_03.txt 22 ms 920 KB
subtask1_04.txt 25 ms 920 KB
subtask1_05.txt 26 ms 904 KB
subtask1_06.txt 20 ms 916 KB
subtask1_07.txt 21 ms 800 KB
subtask1_08.txt 25 ms 916 KB
subtask1_09.txt 24 ms 920 KB
subtask1_10.txt 29 ms 924 KB
subtask1_11.txt 30 ms 920 KB
subtask1_12.txt 24 ms 920 KB
subtask2_01.txt 22 ms 796 KB
subtask2_02.txt 158 ms 848 KB
subtask2_03.txt 67 ms 1044 KB
subtask2_04.txt 28 ms 920 KB
subtask2_05.txt 105 ms 840 KB
subtask2_06.txt 1656 ms 1572 KB
subtask2_07.txt 1721 ms 1320 KB
subtask2_08.txt 1355 ms 1312 KB
subtask2_09.txt 2031 ms 1568 KB
subtask2_10.txt 2032 ms 1704 KB
subtask2_11.txt 2031 ms 1704 KB
subtask2_12.txt 1203 ms 1228 KB
subtask3_01.txt 76 ms 920 KB
subtask3_02.txt 23 ms 912 KB
subtask3_03.txt 1773 ms 1316 KB
subtask3_04.txt 2034 ms 8548 KB
subtask3_05.txt 68 ms 1576 KB
subtask3_06.txt 2031 ms 1440 KB
subtask3_07.txt 2033 ms 2456 KB
subtask3_08.txt 2030 ms 7896 KB
subtask3_09.txt 2031 ms 8552 KB
subtask3_10.txt 2032 ms 8548 KB
subtask3_11.txt 2034 ms 8540 KB
subtask3_12.txt 2032 ms 4648 KB
subtask4_01.txt 2033 ms 8548 KB
subtask4_02.txt 2031 ms 920 KB
subtask4_03.txt 2033 ms 1448 KB
subtask4_04.txt 2032 ms 8544 KB
subtask4_05.txt 2031 ms 904 KB
subtask4_06.txt 2032 ms 932 KB
subtask4_07.txt 27 ms 860 KB
subtask4_08.txt 610 ms 920 KB
subtask4_09.txt 2031 ms 7528 KB
subtask4_10.txt 2033 ms 924 KB
subtask4_11.txt 2032 ms 8548 KB
subtask4_12.txt 2032 ms 8552 KB
subtask4_13.txt 2031 ms 8496 KB
subtask4_14.txt 22 ms 916 KB