結果

問題 No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩
ユーザー mkawa2mkawa2
提出日時 2021-01-23 11:16:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,427 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,208 KB
実行使用メモリ 194,592 KB
最終ジャッジ日時 2023-08-28 20:54:48
合計ジャッジ時間 26,623 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,572 KB
testcase_01 AC 69 ms
71,348 KB
testcase_02 AC 73 ms
75,624 KB
testcase_03 AC 71 ms
75,700 KB
testcase_04 AC 68 ms
71,432 KB
testcase_05 AC 75 ms
71,512 KB
testcase_06 AC 70 ms
71,484 KB
testcase_07 AC 68 ms
71,296 KB
testcase_08 AC 99 ms
76,788 KB
testcase_09 AC 89 ms
76,228 KB
testcase_10 AC 96 ms
76,888 KB
testcase_11 AC 94 ms
76,292 KB
testcase_12 AC 96 ms
76,792 KB
testcase_13 AC 95 ms
76,904 KB
testcase_14 AC 88 ms
75,720 KB
testcase_15 AC 107 ms
77,512 KB
testcase_16 AC 101 ms
76,840 KB
testcase_17 AC 98 ms
76,728 KB
testcase_18 AC 167 ms
81,476 KB
testcase_19 AC 137 ms
79,292 KB
testcase_20 AC 185 ms
81,364 KB
testcase_21 AC 140 ms
80,424 KB
testcase_22 AC 151 ms
79,972 KB
testcase_23 AC 165 ms
80,744 KB
testcase_24 AC 171 ms
81,116 KB
testcase_25 AC 166 ms
80,816 KB
testcase_26 AC 174 ms
81,088 KB
testcase_27 AC 157 ms
80,252 KB
testcase_28 WA -
testcase_29 AC 995 ms
112,704 KB
testcase_30 AC 778 ms
111,016 KB
testcase_31 AC 1,004 ms
130,916 KB
testcase_32 AC 1,720 ms
152,652 KB
testcase_33 AC 723 ms
113,580 KB
testcase_34 AC 1,199 ms
134,604 KB
testcase_35 AC 1,339 ms
126,364 KB
testcase_36 TLE -
testcase_37 AC 449 ms
103,572 KB
testcase_38 AC 1,131 ms
118,144 KB
testcase_39 AC 675 ms
106,248 KB
testcase_40 AC 858 ms
117,992 KB
testcase_41 AC 1,416 ms
120,084 KB
testcase_42 TLE -
testcase_43 AC 1,365 ms
117,780 KB
testcase_44 AC 1,328 ms
131,968 KB
testcase_45 AC 1,149 ms
125,840 KB
testcase_46 AC 1,471 ms
194,592 KB
testcase_47 AC 670 ms
108,588 KB
testcase_48 TLE -
testcase_49 AC 1,736 ms
173,008 KB
testcase_50 TLE -
testcase_51 TLE -
testcase_52 AC 1,465 ms
173,152 KB
testcase_53 TLE -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
権限があれば一括ダウンロードができます

ソースコード

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 >= 0 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:
    l = -10**18
    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(0, bb[0], cc[0], dd[0])
            exit()
        i = find0(bb)
        if i != -1:
            print(aa[0], 0, cc[0], dd[0])
            exit()
    else:
        i = find0(cc)
        if i != -1:
            print(aa[0], bb[0], 0, dd[0])
            exit()
        i = find0(dd)
        if i != -1:
            print(aa[0], bb[0], cc[0], 0)
            exit()

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