結果

問題 No.1334 Multiply or Add
ユーザー chineristACchineristAC
提出日時 2021-01-08 22:33:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,857 bytes
コンパイル時間 140 ms
コンパイル使用メモリ 81,824 KB
実行使用メモリ 119,876 KB
最終ジャッジ日時 2024-04-28 03:59:22
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,480 KB
testcase_01 AC 34 ms
52,224 KB
testcase_02 AC 33 ms
52,608 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 74 ms
98,948 KB
testcase_17 AC 74 ms
99,532 KB
testcase_18 AC 72 ms
98,836 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 79 ms
112,520 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 34 ms
52,772 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 90 ms
101,700 KB
testcase_51 AC 90 ms
101,772 KB
testcase_52 AC 89 ms
102,176 KB
testcase_53 AC 96 ms
101,944 KB
testcase_54 AC 88 ms
102,036 KB
testcase_55 AC 91 ms
100,352 KB
testcase_56 AC 35 ms
53,440 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 33 ms
52,480 KB
testcase_60 AC 34 ms
52,480 KB
testcase_61 AC 36 ms
52,480 KB
testcase_62 AC 34 ms
52,224 KB
testcase_63 AC 33 ms
52,224 KB
testcase_64 AC 32 ms
52,224 KB
testcase_65 AC 35 ms
52,480 KB
testcase_66 AC 72 ms
98,816 KB
testcase_67 AC 64 ms
86,464 KB
testcase_68 AC 41 ms
61,312 KB
testcase_69 AC 80 ms
104,416 KB
testcase_70 AC 79 ms
102,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

check = 1
for i in range(N):
    check *= A[i]
    if check>2**20:
        check = 2**20
        break

if check==2**20:
    L = -1
    R = N
    for i in range(N):
        if A[i]>1:
            if L==-1:
                L = i
            R = i

    res = 0
    if L!=-1:
        res = L + (N-1-R)

    tmp = 1
    for i in range(L,R+1):
        tmp *= A[i]
        tmp %= mod
    res += tmp
    res %= mod
    print(res)
else:
    comp = []
    tmp = 1
    flag = False
    for i in range(N):
        if A[i]==1:
            if flag:
                comp.append(tmp)
                flag = False
            comp.append(1)
        else:
            if not flag:
                tmp = A[i]
                flag = True
            else:
                tmp *= A[i]
                tmp %= mod
    if flag:
        comp.append(tmp)

    n = len(comp)
    L = -1
    R = N
    for i in range(n):
        if comp[i]!=1:
            if L==-1:
                L = i
            R = i

    if L==-1:
        res = N
        print(res)
    elif L==R:
        res = sum(comp)
        print(res%mod)
    else:
        comp = [comp[i] for i in range(L,R+1)]
        new_comp = []
        for i in range(len(comp)):
            if comp[i]!=1:
                new_comp.append(i)

        res = 0
        m = len(new_comp)
        #print(comp)
        #print(new_comp)
        for i in range(2**(m-1)):
            tmp = L + (n-1-R)
            tmp_prod = comp[new_comp[0]]
            for j in range(m-1):
                if i>>j & 1:
                    tmp_prod *= comp[new_comp[j+1]]
                else:
                    tmp += tmp_prod + new_comp[j+1] - new_comp[j] - 1
                    tmp_prod = new_comp[j+1]
            tmp += tmp_prod
            res = max(res,tmp)
        print(res)
0