Submission #15000319


Source Code Expand

Copy
import sys
import numpy as np

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

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

def f(A, N, K):
    A.sort()
    I = (np.abs(A)).argsort()
    A = A[I][::-1]
    if N == K:
        return A
    # 全部負
    if np.all(A < 0):
        if K % 2 == 0:
            return A[:K]
        else:
            return A[-K:]
    # これ以外の場合は、必ず正を実現できる
    pos = A[A >= 0]
    neg = A[A < 0]
    nums = [1]
    if K & 1:
        nums = [pos[0]]
        pos = pos[1:]
        K -= 1
    # K は偶数
    # pos, neg から偶数個ずつセットにする
    if len(pos) & 1:
        pos = pos[:-1]
    if len(neg) & 1:
        neg = neg[:-1]
    pos = pos[::2] * pos[1::2]
    neg = neg[::2] * neg[1::2]
    A = np.concatenate([pos, neg])
    A.sort()
    A = A[::-1]
    return np.concatenate([nums, A[:K // 2]])

MOD = 10**9 + 7
B = f(A, N, K).tolist()
ans = 1
for x in B:
    ans = ans * x % MOD
print(ans)

Submission Info

Submission Time
Task E - Multiplication 4
User maspy
Language Python (3.8.2)
Score 500
Code Size 1115 Byte
Status
Exec Time 237 ms
Memory 40376 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 500 / 500 hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_m01.txt, random_m02.txt, random_m03.txt, random_m04.txt, random_m05.txt, random_m06.txt, random_max01.txt, random_max02.txt, random_mz01.txt, random_mz02.txt, random_mz03.txt, random_p01.txt, random_p02.txt, random_pm00.txt, random_pm01.txt, random_pm02.txt, random_pm03.txt, random_pm11.txt, random_pm12.txt, random_pmz01.txt, random_pmz02.txt, random_pmz03.txt, random_pmz04.txt, random_pmz11.txt, random_pmz12.txt, random_pmz13.txt, random_pz01.txt, random_pz02.txt, random_pz03.txt, random_z01.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
hand_01.txt 199 ms 40112 KB
hand_02.txt 221 ms 40116 KB
hand_03.txt 204 ms 40296 KB
hand_04.txt 214 ms 40376 KB
hand_05.txt 201 ms 40300 KB
random_m01.txt 161 ms 31108 KB
random_m02.txt 140 ms 28244 KB
random_m03.txt 171 ms 32268 KB
random_m04.txt 231 ms 38624 KB
random_m05.txt 204 ms 36356 KB
random_m06.txt 139 ms 27720 KB
random_max01.txt 237 ms 40212 KB
random_max02.txt 199 ms 40052 KB
random_mz01.txt 168 ms 33716 KB
random_mz02.txt 140 ms 27644 KB
random_mz03.txt 134 ms 27192 KB
random_p01.txt 165 ms 33680 KB
random_p02.txt 168 ms 32488 KB
random_pm00.txt 140 ms 29668 KB
random_pm01.txt 145 ms 30560 KB
random_pm02.txt 180 ms 34692 KB
random_pm03.txt 163 ms 31216 KB
random_pm11.txt 169 ms 33472 KB
random_pm12.txt 126 ms 27432 KB
random_pmz01.txt 166 ms 33420 KB
random_pmz02.txt 204 ms 38156 KB
random_pmz03.txt 155 ms 30568 KB
random_pmz04.txt 165 ms 31832 KB
random_pmz11.txt 157 ms 32984 KB
random_pmz12.txt 140 ms 27776 KB
random_pmz13.txt 168 ms 33380 KB
random_pz01.txt 151 ms 31052 KB
random_pz02.txt 202 ms 35580 KB
random_pz03.txt 161 ms 31796 KB
random_z01.txt 162 ms 33528 KB
sample_01.txt 129 ms 26732 KB
sample_02.txt 128 ms 27076 KB
sample_03.txt 128 ms 27128 KB
sample_04.txt 132 ms 27024 KB