Submission #1174220


Source Code Expand

import random, sys
import time
inputs = lambda: map(int, raw_input().split())

random.seed()

h, w, k, t = inputs()
X, Y = h, w
Cars = [inputs() for i in xrange(k)]
Coms = []

com_str = "LRUD-"
dd = [(0, -1), (0, 1), (-1, 0), (1, 0), (0, 0)]
wds = {(0, 0): [1, 2], (1, 0): [2, 0], (0, 1): [3, 1], (1, 1): [0, 3]}

order = range(k)
ds = range(4)

pre = 600

def dist(x0, y0, x1, y1):
    return abs(x0 - x1) + abs(y0 - y1)
def calc_score(L, Cars):
    Pd = 20 + sum(abs(x0 - x1) + abs(y0 - y1) for x0, y0, x1, y1 in Cars)
    Pt = 10 + L * 0.01
    return 10**7 / (Pt * Pd)

X2 = X/2
Y2 = Y/2
L = 0
tries = 10
last = -1
for l in xrange(t):
    update = 0
    current_score = calc_score(l, Cars)
    #print Cars, current_score
    next_score = 0 if l < pre else current_score
    coms = [4]*k
    exist_ = {(x0, y0) for x0, y0, x1, y1 in Cars}
    for _ in xrange(tries if l >= pre and last == -1 else 1):
        coms_tmp = [4]*k
        nCars = [e[:] for e in Cars]
        random.shuffle(order)
        exist = set(exist_)
        for i in order:
            x0, y0, x1, y1 = Cars[i]
            #if x0 == x1 and y0 == y1:
            #    continue

            if (l < pre and abs(x0 - y0) + abs(x1 - y1) > 3) or last != -1:
                random.shuffle(ds)
                wild = random.randint(0, 1) and last == -1
                for d in ds:
                    dx, dy = dd[d]
                    nx = x0 + dx; ny = y0 + dy
                    if not 0 < nx <= X or not 0 < ny <= Y:
                        continue
                    if not wild and dist(x0, y0, x1, y1) <= dist(nx, ny, x1, y1):
                        continue
                    if (nx, ny) not in exist:
                        update = 1
                        exist.add((nx, ny))
                        nCars[i] = (nx, ny, x1, y1)
                        coms_tmp[i] = d
                        break
            elif random.randint(0, 1):
                dds = wds[((x0-1)/X2, (y0-1)/Y2)]
                for d in dds if random.randint(0, 1) else reversed(dds):
                    dx, dy = dd[d]
                    nx = x0 + dx; ny = y0 + dy
                    if 0 < nx <= X and 0 < ny <= Y:
                        if (nx, ny) not in exist:
                            update = 1
                            exist.add((nx, ny))
                            nCars[i] = (nx, ny, x1, y1)
                            coms_tmp[i] = d
                            break
                else:
                    random.shuffle(ds)
                    for d in ds:
                        dx, dy = dd[d]
                        nx = x0 + dx; ny = y0 + dy
                        if not 0 < nx <= X or not 0 < ny <= Y:
                            continue
                        if (nx, ny) not in exist:
                            update = 1
                            exist.add((nx, ny))
                            nCars[i] = (nx, ny, x1, y1)
                            coms_tmp[i] = d
                            break

        score = calc_score(l+1, nCars)
        if next_score < score:
            next_score = score
            coms = coms_tmp
    if l > pre and (current_score == next_score or l == 10000):
        if last == -1:
            last = 100
        elif last == 0 or (update == 0 and last > 0):
            L = l
            break
    for i in xrange(k):
        dx, dy = dd[coms[i]]
        x0, y0, x1, y1 = Cars[i]
        Cars[i] = (x0+dx, y0+dy, x1, y1)
    Coms.append(map(com_str.__getitem__, coms))
    if last > 0:
        last -= 1
sys.stdout.write("%d\n" % L)
sys.stdout.write("\n".join("".join(e) for e in Coms))

Submission Info

Submission Time
Task B - 日本橋大渋滞
User yaketake08
Language Python (2.7.6)
Score 39745
Code Size 3741 Byte
Status AC
Exec Time 2175 ms
Memory 7552 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10 test_11 test_12 test_13 test_14 test_15 test_16 test_17 test_18 test_19 test_20 test_21 test_22 test_23 test_24 test_25 test_26 test_27 test_28 test_29 test_30
Score / Max Score 1832 / 50000 1841 / 50000 2085 / 50000 1571 / 50000 1261 / 50000 1609 / 50000 748 / 50000 1913 / 50000 1649 / 50000 979 / 50000 1535 / 50000 1653 / 50000 1126 / 50000 1520 / 50000 1380 / 50000 1347 / 50000 927 / 50000 1339 / 50000 555 / 50000 1084 / 50000 895 / 50000 1030 / 50000 1040 / 50000 607 / 50000 1269 / 50000 1896 / 50000 1320 / 50000 751 / 50000 1199 / 50000 1784 / 50000
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
test_11 subtask_01_11.txt
test_12 subtask_01_12.txt
test_13 subtask_01_13.txt
test_14 subtask_01_14.txt
test_15 subtask_01_15.txt
test_16 subtask_01_16.txt
test_17 subtask_01_17.txt
test_18 subtask_01_18.txt
test_19 subtask_01_19.txt
test_20 subtask_01_20.txt
test_21 subtask_01_21.txt
test_22 subtask_01_22.txt
test_23 subtask_01_23.txt
test_24 subtask_01_24.txt
test_25 subtask_01_25.txt
test_26 subtask_01_26.txt
test_27 subtask_01_27.txt
test_28 subtask_01_28.txt
test_29 subtask_01_29.txt
test_30 subtask_01_30.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 2121 ms 7552 KB
subtask_01_02.txt AC 2120 ms 6028 KB
subtask_01_03.txt AC 2103 ms 6028 KB
subtask_01_04.txt AC 2120 ms 6028 KB
subtask_01_05.txt AC 2120 ms 6028 KB
subtask_01_06.txt AC 2143 ms 6148 KB
subtask_01_07.txt AC 2118 ms 6028 KB
subtask_01_08.txt AC 2133 ms 6032 KB
subtask_01_09.txt AC 2122 ms 6028 KB
subtask_01_10.txt AC 2137 ms 6028 KB
subtask_01_11.txt AC 2140 ms 6028 KB
subtask_01_12.txt AC 2129 ms 6028 KB
subtask_01_13.txt AC 2136 ms 6028 KB
subtask_01_14.txt AC 2124 ms 6028 KB
subtask_01_15.txt AC 2135 ms 6028 KB
subtask_01_16.txt AC 2121 ms 6032 KB
subtask_01_17.txt AC 2121 ms 6028 KB
subtask_01_18.txt AC 2107 ms 6028 KB
subtask_01_19.txt AC 2175 ms 6028 KB
subtask_01_20.txt AC 2154 ms 6032 KB
subtask_01_21.txt AC 2125 ms 6032 KB
subtask_01_22.txt AC 2157 ms 6028 KB
subtask_01_23.txt AC 2122 ms 6028 KB
subtask_01_24.txt AC 2128 ms 6032 KB
subtask_01_25.txt AC 2107 ms 6032 KB
subtask_01_26.txt AC 2144 ms 6028 KB
subtask_01_27.txt AC 2145 ms 6032 KB
subtask_01_28.txt AC 2143 ms 6028 KB
subtask_01_29.txt AC 2152 ms 6028 KB
subtask_01_30.txt AC 2135 ms 6028 KB