Submission #9656491


Source Code Expand

Copy
function max(x,y){return x<y?y:x}
function min(x,y){return x<y?x:y}
function abs(x){return x<0?-x:x}
function gcd(x,y){return y==0?x:gcd(y,x%y)}
function lcm(x,y){return x/gcd(x,y)*y}

BEGIN {
    FS = RS
    RS = "@"
}
{
    x = 0
    y = 0
    q = 0
    for (i = 1; i <= length($1); ++i) {
        c = substr($1, i, 1)
        if (c == "U") {
            x++
        } else if (c == "D") {
            x--
        } else if (c == "L") {
            y--
        } else if (c == "R") {
            y++
        } else {
            q++
        }
    }
    x = abs(x)
    y = abs(y)
    if ($2 == 1) {
        d = abs(x+q) + y
        d = max(d, abs(x-q) + y)
        d = max(d, x + abs(y+q))
        d = max(d, x + abs(y-q))
        print d
    } else {
        dq = min(x, q)
        x -= dq
        q -= dq
        dq = min(y, q)
        y -= dq
        q -= dq
        if (q > 0) {
            x += q % 2
        }
        print abs(x) + abs(y)
    }
}

Submission Info

Submission Time
Task B - ドローン
User cympfh
Language Awk (mawk 1.3.3)
Score 101
Code Size 1006 Byte
Status
Exec Time 23 ms
Memory 512 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt
Subtask1 100 / 100 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt
All 1 / 1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 10_rand_01.txt, 10_rand_02.txt, 10_rand_03.txt, 10_rand_04.txt, 20_no_question_01.txt, 20_no_question_02.txt, 20_no_question_03.txt, 20_no_question_04.txt, 30_max_01.txt, 30_max_02.txt, 30_max_03.txt, 30_max_04.txt, 40_corner_01.txt, 40_corner_02.txt, 40_corner_03.txt, 40_corner_04.txt, 50_hand_01.txt, 50_hand_02.txt, 50_hand_03.txt, 60_rand_01.txt, 60_rand_02.txt, 60_rand_03.txt, 60_rand_04.txt, 70_no_ques_01.txt, 70_no_ques_02.txt, 70_no_ques_03.txt, 70_no_ques_04.txt, 80_max_01.txt, 80_max_02.txt, 80_max_03.txt, 80_max_04.txt, 90_corner_01.txt, 90_corner_02.txt, 90_corner_03.txt, 90_corner_04.txt
Case Name Status Exec Time Memory
00_example_01.txt 4 ms 380 KB
00_example_02.txt 1 ms 256 KB
00_example_03.txt 1 ms 256 KB
00_example_04.txt 1 ms 256 KB
10_rand_01.txt 3 ms 256 KB
10_rand_02.txt 1 ms 256 KB
10_rand_03.txt 1 ms 256 KB
10_rand_04.txt 2 ms 256 KB
20_no_question_01.txt 3 ms 256 KB
20_no_question_02.txt 1 ms 256 KB
20_no_question_03.txt 1 ms 256 KB
20_no_question_04.txt 2 ms 256 KB
30_max_01.txt 20 ms 512 KB
30_max_02.txt 20 ms 512 KB
30_max_03.txt 20 ms 512 KB
30_max_04.txt 20 ms 512 KB
40_corner_01.txt 19 ms 512 KB
40_corner_02.txt 23 ms 512 KB
40_corner_03.txt 21 ms 512 KB
40_corner_04.txt 20 ms 512 KB
50_hand_01.txt 1 ms 256 KB
50_hand_02.txt 1 ms 256 KB
50_hand_03.txt 1 ms 256 KB
60_rand_01.txt 3 ms 256 KB
60_rand_02.txt 1 ms 256 KB
60_rand_03.txt 1 ms 256 KB
60_rand_04.txt 2 ms 256 KB
70_no_ques_01.txt 3 ms 256 KB
70_no_ques_02.txt 1 ms 256 KB
70_no_ques_03.txt 1 ms 256 KB
70_no_ques_04.txt 2 ms 256 KB
80_max_01.txt 21 ms 512 KB
80_max_02.txt 21 ms 512 KB
80_max_03.txt 21 ms 512 KB
80_max_04.txt 20 ms 512 KB
90_corner_01.txt 22 ms 512 KB
90_corner_02.txt 22 ms 512 KB
90_corner_03.txt 20 ms 512 KB
90_corner_04.txt 20 ms 512 KB