Submission #3601887


Source Code Expand

#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
https://beta.atcoder.jp/contests/abc008/tasks/abc008_2
"""

import sys
from inspect import currentframe
from itertools import permutations
import math
import numpy as np
from collections import namedtuple

sys.setrecursionlimit(100000)

def debug_print(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)


W, H = map(int, input().split())
N = int(input())
Point = namedtuple('Point', ['x', 'y'])
Area = namedtuple('Area', ['bottom_left', 'top_right'])
cranes = [Point(*map(int, input().split())) for _ in range(N)]
earn_memo = {}

def is_in_area(area, point):
    return area.bottom_left.x <= point.x < area.top_right.x and area.bottom_left.y <= point.y < area.top_right.y

# areaで表わされる座標をpoint=(x,y)で4分割したareaを計算
# 但し、座標がareaに入っていなければ空、端なら1-2の領域となる
def split4(area, point):
    bl = area.bottom_left
    tr = area.top_right
    areas = [Area(Point(bl.x, bl.y), Point(point.x, point.y)),
             Area(Point(bl.x, point.y + 1), Point(point.x, tr.y)),
             Area(Point(point.x + 1, bl.y), Point(tr.x, point.y)),
             Area(Point(point.x + 1, point.y + 1), Point(tr.x, tr.y))]
    return list(filter(lambda a: a.bottom_left.x < a.top_right.x and a.bottom_left.y < a.top_right.y, areas))

def earn_gold(area):
    if area in earn_memo.keys():
        return earn_memo[area]
    earns = []
    for crane in cranes:
        if is_in_area(area, crane):
            sub_areas = split4(area, crane)
            earn_this_split = (area.top_right.y - area.bottom_left.y) + (area.top_right.x - area.bottom_left.x) - 1
            earns.append(sum([earn_gold(sub_area) for sub_area in sub_areas]) + earn_this_split)
        else:
            earns.append(0)
    earn = max(earns)
    earn_memo[area] = earn
    return earn

print(earn_gold(Area(Point(1,1), Point(W + 1, H + 1))))

Submission Info

Submission Time
Task D - 金塊ゲーム
User terakoji
Language Python (3.4.3)
Score 100
Code Size 2103 Byte
Status AC
Exec Time 730 ms
Memory 16700 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 80 / 80 19 / 19 1 / 1
Status
AC × 3
AC × 25
AC × 50
AC × 75
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 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, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.txt
Subtask2 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, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.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, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.txt
Subtask3 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, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt, subtask1_25.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, subtask2_13.txt, subtask2_14.txt, subtask2_15.txt, subtask2_16.txt, subtask2_17.txt, subtask2_18.txt, subtask2_19.txt, subtask2_20.txt, subtask2_21.txt, subtask2_22.txt, subtask2_23.txt, subtask2_24.txt, subtask2_25.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, subtask3_13.txt, subtask3_14.txt, subtask3_15.txt, subtask3_16.txt, subtask3_17.txt, subtask3_18.txt, subtask3_19.txt, subtask3_20.txt, subtask3_21.txt, subtask3_22.txt, subtask3_23.txt, subtask3_24.txt, subtask3_25.txt
Case Name Status Exec Time Memory
sample_01.txt AC 169 ms 13296 KB
sample_02.txt AC 167 ms 13268 KB
sample_03.txt AC 173 ms 13260 KB
subtask1_01.txt AC 168 ms 13296 KB
subtask1_02.txt AC 172 ms 13296 KB
subtask1_03.txt AC 176 ms 13308 KB
subtask1_04.txt AC 175 ms 13296 KB
subtask1_05.txt AC 169 ms 13296 KB
subtask1_06.txt AC 171 ms 13260 KB
subtask1_07.txt AC 170 ms 13268 KB
subtask1_08.txt AC 172 ms 13264 KB
subtask1_09.txt AC 175 ms 13304 KB
subtask1_10.txt AC 171 ms 13308 KB
subtask1_11.txt AC 172 ms 13264 KB
subtask1_12.txt AC 171 ms 13296 KB
subtask1_13.txt AC 169 ms 13296 KB
subtask1_14.txt AC 169 ms 13304 KB
subtask1_15.txt AC 172 ms 13260 KB
subtask1_16.txt AC 177 ms 13308 KB
subtask1_17.txt AC 173 ms 13260 KB
subtask1_18.txt AC 173 ms 13284 KB
subtask1_19.txt AC 175 ms 13264 KB
subtask1_20.txt AC 173 ms 13308 KB
subtask1_21.txt AC 178 ms 13296 KB
subtask1_22.txt AC 177 ms 13260 KB
subtask1_23.txt AC 176 ms 13260 KB
subtask1_24.txt AC 177 ms 13308 KB
subtask1_25.txt AC 175 ms 13308 KB
subtask2_01.txt AC 209 ms 13504 KB
subtask2_02.txt AC 208 ms 13444 KB
subtask2_03.txt AC 272 ms 14140 KB
subtask2_04.txt AC 284 ms 14128 KB
subtask2_05.txt AC 353 ms 14484 KB
subtask2_06.txt AC 420 ms 15120 KB
subtask2_07.txt AC 406 ms 14604 KB
subtask2_08.txt AC 408 ms 14596 KB
subtask2_09.txt AC 662 ms 15948 KB
subtask2_10.txt AC 646 ms 15964 KB
subtask2_11.txt AC 634 ms 15876 KB
subtask2_12.txt AC 669 ms 15968 KB
subtask2_13.txt AC 424 ms 15144 KB
subtask2_14.txt AC 413 ms 15160 KB
subtask2_15.txt AC 181 ms 13304 KB
subtask2_16.txt AC 414 ms 14584 KB
subtask2_17.txt AC 691 ms 15640 KB
subtask2_18.txt AC 670 ms 15976 KB
subtask2_19.txt AC 647 ms 15968 KB
subtask2_20.txt AC 654 ms 15964 KB
subtask2_21.txt AC 656 ms 15848 KB
subtask2_22.txt AC 659 ms 15976 KB
subtask2_23.txt AC 661 ms 15996 KB
subtask2_24.txt AC 664 ms 16052 KB
subtask2_25.txt AC 689 ms 15968 KB
subtask3_01.txt AC 171 ms 13256 KB
subtask3_02.txt AC 213 ms 13656 KB
subtask3_03.txt AC 209 ms 13464 KB
subtask3_04.txt AC 245 ms 13852 KB
subtask3_05.txt AC 330 ms 14464 KB
subtask3_06.txt AC 287 ms 14372 KB
subtask3_07.txt AC 287 ms 14304 KB
subtask3_08.txt AC 418 ms 15252 KB
subtask3_09.txt AC 448 ms 15560 KB
subtask3_10.txt AC 699 ms 16296 KB
subtask3_11.txt AC 682 ms 16580 KB
subtask3_12.txt AC 730 ms 16656 KB
subtask3_13.txt AC 721 ms 16596 KB
subtask3_14.txt AC 689 ms 16320 KB
subtask3_15.txt AC 692 ms 16440 KB
subtask3_16.txt AC 670 ms 16304 KB
subtask3_17.txt AC 718 ms 16668 KB
subtask3_18.txt AC 361 ms 14520 KB
subtask3_19.txt AC 691 ms 16696 KB
subtask3_20.txt AC 427 ms 15244 KB
subtask3_21.txt AC 725 ms 16684 KB
subtask3_22.txt AC 711 ms 16672 KB
subtask3_23.txt AC 696 ms 16700 KB
subtask3_24.txt AC 705 ms 16656 KB
subtask3_25.txt AC 688 ms 16664 KB