Submission #17343567


Source Code Expand

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], i8[:], i8[:]), cache=True)
def f(L, W, A):
    N = len(A)
    X = np.zeros(N, np.int64)
    Acum = np.zeros(N + 1, np.int64)
    Acum[1:] = np.cumsum(A)
    for n in range(1, N):
        # n 人目を並べるとき。
        x = 0
        for i in range(n):
            # [i, n] の重さ
            wt = Acum[n + 1] - Acum[i]
            # その重さで破壊される橋の最大の長さ
            k = np.searchsorted(W, wt) - 1
            l = L[k]
            x = max(x, X[i] + l)
        X[n] = x
    return X[-1]

def main(N, A, LW, perms):
    L, W = LW[::2], LW[1::2]
    if W.min() < A.max():
        return -1
    INF = 1 << 60
    # 番兵
    L = np.append(L, 0)
    W = np.append(W, 0)
    L = np.append(L, INF)
    W = np.append(W, INF)
    # 重さ順に並べる
    argsort = W.argsort()
    L, W = L[argsort], W[argsort]
    # ある重さに対して、最も長いもの
    for i in range(len(L) - 1):
        L[i + 1] = max(L[i], L[i + 1])
    ans = INF
    for p in perms:
        x = f(L, W, A[p])
        ans = min(ans, x)
    return ans

N, M = map(int, readline().split())
perms = np.array(list(itertools.permutations(range(N))))
A = np.array(readline().split(), np.int64)
LW = np.array(read().split(), np.int64)

print(main(N, A, LW, perms))

Submission Info

Submission Time
Task C - Camels and Bridge
User maspy
Language Python (3.8.2)
Score 500
Code Size 1553 Byte
Status AC
Exec Time 772 ms
Memory 122368 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 64
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All ng_01.txt, ng_02.txt, ng_03.txt, ng_04.txt, ng_05.txt, ng_06.txt, ng_07.txt, ng_08.txt, ng_09.txt, ng_10.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, small_07.txt, small_08.txt, small_09.txt, small_10.txt, small_11.txt, small_12.txt, small_13.txt, small_14.txt, small_15.txt, small_16.txt, small_17.txt, small_18.txt, small_19.txt, small_20.txt
Case Name Status Exec Time Memory
ng_01.txt AC 634 ms 121512 KiB
ng_02.txt AC 609 ms 122048 KiB
ng_03.txt AC 615 ms 121336 KiB
ng_04.txt AC 613 ms 121412 KiB
ng_05.txt AC 603 ms 121244 KiB
ng_06.txt AC 589 ms 113140 KiB
ng_07.txt AC 579 ms 113360 KiB
ng_08.txt AC 580 ms 113740 KiB
ng_09.txt AC 578 ms 113748 KiB
ng_10.txt AC 573 ms 112696 KiB
random_01.txt AC 752 ms 122368 KiB
random_02.txt AC 770 ms 122140 KiB
random_03.txt AC 743 ms 121252 KiB
random_04.txt AC 757 ms 122068 KiB
random_05.txt AC 752 ms 121420 KiB
random_06.txt AC 768 ms 121348 KiB
random_07.txt AC 750 ms 122144 KiB
random_08.txt AC 754 ms 120844 KiB
random_09.txt AC 749 ms 121352 KiB
random_10.txt AC 772 ms 122132 KiB
random_11.txt AC 665 ms 113084 KiB
random_12.txt AC 662 ms 113720 KiB
random_13.txt AC 670 ms 113112 KiB
random_14.txt AC 649 ms 113744 KiB
random_15.txt AC 664 ms 112596 KiB
random_16.txt AC 663 ms 113744 KiB
random_17.txt AC 664 ms 112576 KiB
random_18.txt AC 658 ms 113316 KiB
random_19.txt AC 660 ms 112700 KiB
random_20.txt AC 661 ms 113888 KiB
random_21.txt AC 528 ms 105976 KiB
random_22.txt AC 548 ms 107612 KiB
random_23.txt AC 553 ms 106676 KiB
random_24.txt AC 542 ms 106572 KiB
random_25.txt AC 534 ms 106960 KiB
random_26.txt AC 547 ms 106828 KiB
random_27.txt AC 545 ms 106920 KiB
random_28.txt AC 531 ms 106772 KiB
random_29.txt AC 530 ms 105964 KiB
random_30.txt AC 531 ms 106764 KiB
sample_01.txt AC 524 ms 106088 KiB
sample_02.txt AC 505 ms 105604 KiB
sample_03.txt AC 629 ms 113344 KiB
sample_04.txt AC 635 ms 113104 KiB
small_01.txt AC 643 ms 113164 KiB
small_02.txt AC 661 ms 113324 KiB
small_03.txt AC 644 ms 113892 KiB
small_04.txt AC 642 ms 113272 KiB
small_05.txt AC 654 ms 113744 KiB
small_06.txt AC 653 ms 113376 KiB
small_07.txt AC 651 ms 112700 KiB
small_08.txt AC 661 ms 113160 KiB
small_09.txt AC 653 ms 112644 KiB
small_10.txt AC 659 ms 113076 KiB
small_11.txt AC 654 ms 113156 KiB
small_12.txt AC 652 ms 113068 KiB
small_13.txt AC 657 ms 113156 KiB
small_14.txt AC 641 ms 112996 KiB
small_15.txt AC 655 ms 113720 KiB
small_16.txt AC 661 ms 113200 KiB
small_17.txt AC 654 ms 112704 KiB
small_18.txt AC 659 ms 112724 KiB
small_19.txt AC 660 ms 113084 KiB
small_20.txt AC 660 ms 113000 KiB