結果
問題 | No.1334 Multiply or Add |
ユーザー | chineristAC |
提出日時 | 2021-01-08 22:33:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,857 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 119,168 KB |
最終ジャッジ日時 | 2024-11-16 13:28:39 |
合計ジャッジ時間 | 8,209 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,480 KB |
testcase_01 | AC | 45 ms
52,096 KB |
testcase_02 | AC | 38 ms
52,096 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 | 80 ms
98,432 KB |
testcase_17 | AC | 87 ms
99,072 KB |
testcase_18 | AC | 87 ms
98,816 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 92 ms
112,000 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 | 37 ms
51,968 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 | 103 ms
101,504 KB |
testcase_51 | AC | 102 ms
101,632 KB |
testcase_52 | AC | 104 ms
102,016 KB |
testcase_53 | AC | 105 ms
101,504 KB |
testcase_54 | AC | 106 ms
102,144 KB |
testcase_55 | AC | 112 ms
99,840 KB |
testcase_56 | AC | 38 ms
52,096 KB |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | AC | 37 ms
52,096 KB |
testcase_60 | AC | 39 ms
52,096 KB |
testcase_61 | AC | 38 ms
52,096 KB |
testcase_62 | AC | 38 ms
51,968 KB |
testcase_63 | AC | 38 ms
52,096 KB |
testcase_64 | AC | 37 ms
51,712 KB |
testcase_65 | AC | 43 ms
51,712 KB |
testcase_66 | AC | 95 ms
98,432 KB |
testcase_67 | AC | 80 ms
85,888 KB |
testcase_68 | AC | 52 ms
60,544 KB |
testcase_69 | AC | 103 ms
104,064 KB |
testcase_70 | AC | 92 ms
102,784 KB |
ソースコード
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)