結果

問題 No.110 しましまピラミッド
ユーザー flippergoflippergo
提出日時 2021-01-01 16:48:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 614 ms / 5,000 ms
コード長 1,748 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 77,312 KB
最終ジャッジ日時 2024-04-19 19:55:07
合計ジャッジ時間 6,135 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
64,384 KB
testcase_01 AC 38 ms
58,496 KB
testcase_02 AC 35 ms
51,712 KB
testcase_03 AC 34 ms
52,224 KB
testcase_04 AC 34 ms
52,224 KB
testcase_05 AC 39 ms
57,216 KB
testcase_06 AC 44 ms
62,080 KB
testcase_07 AC 34 ms
52,480 KB
testcase_08 AC 44 ms
61,312 KB
testcase_09 AC 594 ms
76,988 KB
testcase_10 AC 56 ms
70,272 KB
testcase_11 AC 161 ms
77,264 KB
testcase_12 AC 44 ms
61,440 KB
testcase_13 AC 35 ms
52,352 KB
testcase_14 AC 49 ms
66,048 KB
testcase_15 AC 51 ms
67,200 KB
testcase_16 AC 37 ms
57,984 KB
testcase_17 AC 231 ms
76,416 KB
testcase_18 AC 34 ms
52,224 KB
testcase_19 AC 155 ms
76,672 KB
testcase_20 AC 36 ms
52,480 KB
testcase_21 AC 46 ms
58,624 KB
testcase_22 AC 57 ms
67,072 KB
testcase_23 AC 153 ms
76,416 KB
testcase_24 AC 526 ms
76,672 KB
testcase_25 AC 55 ms
69,504 KB
testcase_26 AC 50 ms
65,920 KB
testcase_27 AC 598 ms
76,800 KB
testcase_28 AC 614 ms
77,312 KB
testcase_29 AC 602 ms
76,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product
Nw = int(input())
W = list(map(int,input().split()))
Nb = int(input())
B = list(map(int,input().split()))
hmax = 0
for x in product((0,1),repeat=Nw):
    D = []
    for i in range(Nw):
        if x[i]==1:
            D.append(W[i])
    D = sorted(D,reverse=True)
    for y in product((0,1),repeat=Nb):
        if abs(sum(x)-sum(y))>1:continue
        if sum(x)+sum(y)==0:continue
        E = []
        for j in range(Nb):
            if y[j]==1:
                E.append(B[j])
        E = sorted(E,reverse=True)
        if len(D)>len(E):
            flag = 0
            for i in range(len(D)-1):
                if D[i]>E[i]>D[i+1]:continue
                flag = 1
                break
            if flag==0:
                h = len(D)+len(E)
                hmax = max(hmax,h)
        elif len(E)>len(D):
            flag = 0
            for i in range(len(E)-1):
                if E[i]>D[i]>E[i+1]:continue
                flag = 1
                break
            if flag==0:
                h = len(E)+len(D)
                hmax = max(hmax,h)
        else:
            if D[0]>E[0]:
                flag = 0
                for i in range(len(D)-1):
                    if D[i]>E[i]>D[i+1]:continue
                    flag = 1
                    break
                if flag==0 and D[-1]>E[-1]:
                    h = len(D)+len(E)
                    hmax = max(hmax,h)
            elif E[0]>D[0]:
                flag = 0
                for i in range(len(E)-1):
                    if E[i]>D[i]>E[i+1]:continue
                    flag = 1
                    break
                if flag==0 and E[-1]>D[-1]:
                    h = len(D)+len(E)
                    hmax = max(hmax,h)
print(hmax)
0