結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー mkawa2mkawa2
提出日時 2021-01-23 10:51:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,402 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 241,472 KB
最終ジャッジ日時 2024-06-09 15:10:45
合計ジャッジ時間 39,039 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,812 KB
testcase_01 AC 39 ms
53,788 KB
testcase_02 AC 43 ms
59,776 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 51 ms
64,040 KB
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 WA -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 WA -
testcase_40 RE -
testcase_41 RE -
testcase_42 WA -
testcase_43 RE -
testcase_44 WA -
testcase_45 RE -
testcase_46 WA -
testcase_47 WA -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 WA -
testcase_54 WA -
testcase_55 RE -
testcase_56 WA -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 AC 39 ms
53,716 KB
testcase_73 AC 39 ms
54,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**19
# md = 998244353
md = 10**9+7

def mulall(aa, bb):
    pos = []
    neg = []
    zero = 0
    for i, a in enumerate(aa):
        for j, b in enumerate(bb):
            if a*b == 0: zero += 1
            elif a*b > 0: pos.append((a*b, i, j))
            else: neg.append((a*b, i, j))
    pos.sort(key=lambda x: x[0])
    neg.sort(key=lambda x: x[0])
    return pos, neg, zero

def ok1(m):
    cnt = 0
    if abp and cdn:
        idx = len(cdn)-1
        for x, i, j in abp[::-1]:
            while idx >= 0 and cdn[idx][0]*x >= m:
                idx -= 1
            if idx < 0: break
            cnt += idx+1
    if abn and cdp:
        idx = len(abn)-1
        for x, i, j in cdp[::-1]:
            while idx >= 0 and abn[idx][0]*x >= m:
                idx -= 1
            if idx < 0: break
            cnt += idx+1
    return cnt < s

def ok2(m):
    cnt = 0
    if abp and cdp:
        idx = len(cdp)-1
        for x, i, j in abp:
            while idx >= 0 and cdp[idx][0]*x >= m:
                idx -= 1
            if idx < 0: break
            cnt += idx+1
    if abn and cdn:
        idx = 0
        for x, i, j in abn[::-1]:
            while idx < len(cdn) and cdn[idx][0]*x >= m:
                idx += 1
            if idx >= len(cdn): break
            cnt += len(cdn)-idx
    return cnt < s

def findindex1(l):
    if abp and cdn:
        idx = 0
        for x, i, j in abp:
            while idx < len(cdn) and x*cdn[idx][0] < l:
                idx += 1
            if idx == len(cdn): break
            if x*cdn[idx][0] == l:
                print(l)
                print(aa[i], bb[j], cc[cdn[idx][1]], dd[cdn[idx][2]])
                return
    if abn and cdp:
        idx = 0
        for x, i, j in cdp:
            while idx < len(abn) and x*abn[idx][0] < l:
                idx += 1
            if idx == len(abn): break
            if x*abn[idx][0] == l:
                print(l)
                print(aa[abn[idx][1]], bb[abn[idx][2]], cc[i], dd[j])
                return

def findindex2(l):
    if abp and cdp:
        idx = len(cdp)-1
        for x, i, j in abp:
            while idx < len(cdp) and x*cdp[idx][0] > l:
                idx -= 1
            if idx < 0: break
            if x*cdp[idx][0] == l:
                print(l)
                print(aa[i], bb[j], cc[cdp[idx][1]], dd[cdp[idx][2]])
                return
    idx = len(cdn)-1
    for x, i, j in abn:
        while idx >= 0 and x*cdn[idx][0] < l:
            idx -= 1
        if idx < 0: break
        if x*cdn[idx][0] == l:
            print(l)
            print(aa[i], bb[j], cc[cdn[idx][1]], dd[cdn[idx][2]])
            return

def find0(aa):
    for i, a in enumerate(aa):
        if a == 0: return i
    return -1

an, bn, cn, dn, s = MI()
aa = LI()
bb = LI()
cc = LI()
dd = LI()

abp, abn, abz = mulall(aa, bb)
cdp, cdn, cdz = mulall(cc, dd)
# print(abp, abn, cdp, cdn)

if len(abp)*len(cdn)+len(abn)*len(cdp) >= s:
    print("minus")
    l = -10**9
    r = 0
    while l+1 < r:
        m = (l+r)//2
        if ok1(m): l = m
        else: r = m
    findindex1(l)

elif len(abp)*len(cdn)+len(abn)*len(cdp)+abz*(cn+dn)+cdz*(an+bn) >= s:
    print(0)
    if abz:
        i = find0(aa)
        if i != -1:
            print(i, 0, 0, 0)
            exit()
        i = find0(bb)
        if i != -1:
            print(0, i, 0, 0)
            exit()
    else:
        i = find0(cc)
        if i != -1:
            print(0, 0, i, 0)
            exit()
        i = find0(dd)
        if i != -1:
            print(0, 0, 0, i)
            exit()

else:
    s -= len(abp)*len(cdn)+len(abn)*len(cdp)+abz*(cn+dn)+cdz*(an+bn)
    l = 0
    r = 10**9
    while l+1 < r:
        m = (l+r)//2
        if ok2(m): l = m
        else: r = m
    findindex2(l)
0