結果
問題 | No.1334 Multiply or Add |
ユーザー | leaf_1415 |
提出日時 | 2021-01-08 23:02:19 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,962 bytes |
コンパイル時間 | 4,517 ms |
コンパイル使用メモリ | 89,272 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-16 15:10:46 |
合計ジャッジ時間 | 6,861 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | AC | 2 ms
5,248 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 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
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 | WA | - |
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 | 80 ms
6,528 KB |
testcase_51 | AC | 82 ms
6,656 KB |
testcase_52 | AC | 82 ms
6,656 KB |
testcase_53 | AC | 80 ms
6,528 KB |
testcase_54 | AC | 80 ms
6,528 KB |
testcase_55 | AC | 88 ms
6,656 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | AC | 64 ms
6,144 KB |
testcase_67 | AC | 44 ms
5,248 KB |
testcase_68 | AC | 3 ms
5,248 KB |
testcase_69 | AC | 73 ms
6,400 KB |
testcase_70 | AC | 71 ms
6,272 KB |
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #include <complex> #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 #define mod 1000000007 using namespace std; typedef long long llint; typedef long long ll; typedef pair<llint, llint> P; ll n; ll a[200005]; ll dp[105]; deque<ll> deq; ll M = 1e18; int main(void) { cin >> n; rep(i, 1, n){ cin >> a[i]; deq.push_back(a[i]); } ll add = 0; while(deq.size() && deq.front() == 1) deq.pop_front(), add++; while(deq.size() && deq.back() == 1) deq.pop_back(), add++; ll mul = 1; bool flag = false; for(auto x : deq){ if(x >= M / mul){ flag = true; break; } mul *= x; } if(flag){ ll ans = 1; for(auto x : deq) ans *= x, ans %= mod; ans += add, ans %= mod; cout << ans << endl; return 0; } for(auto x : deq) cout<< x << " "; cout << endl; vector<ll> vec, vec2; mul = 1; ll cnt = 0; for(auto x : deq){ if(x == 1){ if(cnt == 0){ vec.push_back(mul); cnt = 1; } else cnt++; } else{ if(cnt > 0){ vec2.push_back(cnt); mul = x; cnt = 0; } else mul *= x; } } vec.push_back(mul); vec2.push_back(cnt); //for(auto x : vec) cout<< x << " "; cout << endl; //for(auto x : vec2) cout<< x << " "; cout << endl; ll m = vec.size(); rep(i, 0, m) dp[i] = -inf; dp[0] = 0; rep(i, 0, m-1){ rep(j, i+1, m){ ll mul = 1; rep(k, i+1, j) mul *= vec[k-1]; chmax(dp[j], dp[i] + mul + vec2[j-1]); } } //rep(i, 0, m) cout << dp[i] << " "; cout<< endl; ll ans = (dp[m] + add) % mod; cout << ans << endl; return 0; }