Submission #3027468


Source Code Expand

#! /usr/bin/env python3

import math

def solve(h, w):

    y = math.floor(h / 2)

    x = 1
    res = 10**12

    while x <= w / 2:
        x2 = math.floor((w - x) / 2) + x
        areas = [x * h, (x2 - x) * h, (w - x2) * h]
        areas.sort()

        diff = areas[2] - areas[0]
        if diff < res:
            res = diff

        areas = [x * h, (w - x) * y, (w - x) * (h - y)]
        areas.sort()

        diff = areas[2] - areas[0]

        if diff < res:
            res = diff
        
        x += 1

    return(res)


h, w = map(int, input().split())

print(min(solve(h, w), solve(w, h)))

Submission Info

Submission Time
Task C - Chocolate Bar
User eris_c
Language Python (3.4.3)
Score 400
Code Size 640 Byte
Status AC
Exec Time 173 ms
Memory 3064 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 20
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt
Case Name Status Exec Time Memory
0_00.txt AC 18 ms 3064 KB
0_01.txt AC 18 ms 3064 KB
0_02.txt AC 17 ms 3064 KB
0_03.txt AC 91 ms 3064 KB
0_04.txt AC 173 ms 3064 KB
1_00.txt AC 17 ms 3064 KB
1_01.txt AC 94 ms 3064 KB
1_02.txt AC 75 ms 3064 KB
1_03.txt AC 92 ms 3064 KB
1_04.txt AC 65 ms 3064 KB
1_05.txt AC 107 ms 3064 KB
1_06.txt AC 153 ms 3064 KB
1_07.txt AC 94 ms 3064 KB
1_08.txt AC 95 ms 3064 KB
1_09.txt AC 111 ms 3064 KB
1_10.txt AC 137 ms 3064 KB
1_11.txt AC 66 ms 3064 KB
1_12.txt AC 127 ms 3064 KB
1_13.txt AC 93 ms 3064 KB
1_14.txt AC 63 ms 3064 KB