結果

問題 No.110 しましまピラミッド
ユーザー tnodino
提出日時 2022-06-08 21:59:57
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 3,560 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-21 05:15:50
合計ジャッジ時間 21,590 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

def check(s, t):
    for i in range(len(s)):
        if t[i] <= s[i]:
            return False
        if s[i] <= t[i+1]:
            return False
    return True

N = int(input())
W = list(map(int,input().split()))
M = int(input())
B = list(map(int,input().split()))
W.sort(reverse=True)
B.sort(reverse=True)
ans = 0
for bit_w in range(1<<N):
    for bit_b in range(1<<M):
        if abs(bin(bit_w).count('1') - bin(bit_b).count('1')) > 1:
            continue
        s = []
        t = []
        for i in range(N):
            if bit_w & (1<<i):
                s.append(W[i])
        for i in range(M):
            if bit_b & (1<<i):
                t.append(B[i])
        if len(s) == len(t):
            if check(s, [100] + t) or check(t, [100] + s):
                ans = max(ans, len(s)*2)
        else:
            if len(s) > len(t):
                s,t = t,s
            if check(s, t):
                ans = max(ans, len(s)*2+1)
print(ans)
0