結果
問題 | No.1334 Multiply or Add |
ユーザー | XD |
提出日時 | 2021-11-17 16:04:42 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,188 bytes |
コンパイル時間 | 1,826 ms |
コンパイル使用メモリ | 169,752 KB |
実行使用メモリ | 10,584 KB |
最終ジャッジ日時 | 2024-06-06 04:48:50 |
合計ジャッジ時間 | 4,550 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
7,628 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
7,624 KB |
testcase_03 | AC | 5 ms
8,264 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 5 ms
8,264 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 4 ms
7,620 KB |
testcase_11 | AC | 4 ms
7,752 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 4 ms
7,752 KB |
testcase_17 | AC | 5 ms
8,132 KB |
testcase_18 | AC | 4 ms
7,884 KB |
testcase_19 | AC | 4 ms
7,624 KB |
testcase_20 | AC | 5 ms
7,628 KB |
testcase_21 | AC | 4 ms
7,752 KB |
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 | 7 ms
9,668 KB |
testcase_51 | AC | 7 ms
9,804 KB |
testcase_52 | AC | 7 ms
9,672 KB |
testcase_53 | AC | 6 ms
9,668 KB |
testcase_54 | AC | 7 ms
10,060 KB |
testcase_55 | AC | 7 ms
9,672 KB |
testcase_56 | WA | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | AC | 2 ms
6,944 KB |
testcase_60 | WA | - |
testcase_61 | AC | 3 ms
6,940 KB |
testcase_62 | AC | 2 ms
7,496 KB |
testcase_63 | AC | 2 ms
7,496 KB |
testcase_64 | AC | 3 ms
7,624 KB |
testcase_65 | AC | 1 ms
6,940 KB |
testcase_66 | AC | 6 ms
9,676 KB |
testcase_67 | AC | 5 ms
9,544 KB |
testcase_68 | AC | 2 ms
7,496 KB |
testcase_69 | AC | 7 ms
9,548 KB |
testcase_70 | AC | 6 ms
9,672 KB |
ソースコード
#include <bits/stdc++.h> #define forn(i,s,t) for(register int i=(s); i<=(t); ++i) #define forl(i,s,t) for(register i64 i=(s); i<=(t); ++i) #define form(i,s,t) for(register int i=(s); i>=(t); --i) #define rep(i,s,t) for(register int i=(s); i<(t); ++i) #define IT(u) for(register int i=G[u]; i; i=E[i].nxt) using namespace std; namespace FASTIO { const int SIZ = 1 << 26 | 1; char ibuf[SIZ], obuf[SIZ], *iS = ibuf, *iT = ibuf, *oS = obuf, *oT = obuf + SIZ - 1, qwq[60], qaq; #define gc() (iS == iT && (iT = (iS = ibuf) + fread(ibuf, 1, SIZ, stdin), iS == iT) ? EOF : *iS++) template<typename T> inline void Rdn(T& A) { register bool fl = 0; register char ch = gc(); A = 0; while(!isdigit(ch)) fl = (ch == '-'), ch = gc(); while(isdigit(ch)) A = (A * 10) + (ch & 15), ch = gc(); fl && (A = -A); } inline void Rdn(char& c) {while((c = gc()) == ' ' || c == '\n' || c == '\r');} inline void Rdn(char* s) { while((*s = gc()) == ' ' || *s == '\n' || *s == '\r') ; if(*s == EOF) return ; while(*s != ' ' && *s != '\n' && *s != '\r' && *s != EOF) *(++s) = gc(); *s = 0; } template<typename T, typename ...U> inline void Rdn(T& A, U& ...B) {Rdn(A), Rdn(B...);} inline void flush() {fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;} inline void pc(char c) {*oS ++ = c; if(oS == oT) flush();} template<typename T> inline void Wtn(T A) { if(!A) return pc('0'); if(A < 0) pc('-'), A = -A; while(A) qwq[++qaq] = A % 10 + '0', A /= 10; while(qaq) pc(qwq[qaq -- ]); } inline void Wtn(char A) {pc(A);} inline void Wtn(char *s) {while(*s) pc(*s), ++s;} inline void Wtn(const char *s) {while(*s) pc(*s), ++s;} template<typename T, typename ...U> inline void Wtn(T A, U ...B) {Wtn(A), Wtn(B...);} #undef gc } using FASTIO :: Rdn; using FASTIO :: Wtn; using FASTIO :: flush; const int Mod = 1e9 + 7; namespace Modint { struct Mint { int res; Mint() {} Mint(int _r) : res(_r) {} inline friend Mint operator + (const Mint& A, const Mint& B) { return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod) : (A.res + B.res)); } inline friend Mint operator - (const Mint& A, const Mint& B) {return A + Mint(Mod - B.res); } inline friend Mint operator * (const Mint& A, const Mint& B) {return Mint(1ll * A.res * B.res % Mod); } inline friend Mint& operator += (Mint& A, const Mint& B) {return A = A + B; } inline friend Mint& operator -= (Mint& A, const Mint& B) {return A = A - B; } inline friend Mint& operator *= (Mint& A, const Mint& B) {return A = A * B; } inline friend Mint q_pow(Mint p, int k = Mod - 2) { Mint res(1); for (; k; k >>= 1, p *= p) (k & 1) && (res *= p, 0); return res; } } ; } using Modint :: Mint; typedef long long i64; typedef double f64; typedef unsigned long long u64; typedef pair<i64, i64> pii; typedef pair<int, u64> piu; const int N = 2e5 + 5; const i64 INF = 1e18; inline void init() {} struct node { int l, r, val; node() {} node(int _l, int _r, int _v) : l(_l), r(_r), val(_v) {} } b[N]; int n, a[N], m, non[N], s; inline void solve() { Rdn(n); int Prod = 1; bool GG = 0; forn (i, 1, n) { Rdn(a[i]); if (GG || 1ll * Prod * a[i] > n) GG = 1; else Prod *= a[i]; } if (GG) { int now = 1; Mint res(0), Prd(1); while (now <= n && a[now] == 1) res += Mint(1), ++now; int nnw = n; while (nnw > now && a[nnw] == 1) res += Mint(1), nnw--; forn (i, now, nnw) Prd *= Mint(a[i]); res += Prd; Wtn(res.res, '\n'); return ; } int Rdx = 0; forn (l, 1, n) { int r = l; int tmp(a[l]); while (r < n && (a[r + 1] > 1) == (a[l] > 1)) ++r, tmp *= a[r]; b[++m] = node(l, r, tmp); Wtn("[", l, ", ", r, "]\n"); if (l == 1 && tmp == 1) --m, Rdx += r - l + 1; else if (r == n && tmp == 1) --m, Rdx += r - l + 1; else if (tmp == 1) non[s++] = m; l = r; } int ans = 1; b[0] = b[m + 1] = node(0, 0, 1); rep (S, 0, 1 << s) { int res = b[1].val, lst = b[1].val; rep (i, 0, s) { if (S >> i & 1) res -= lst, lst *= b[non[i] + 1].val, res += lst; else res += b[non[i]].r - b[non[i]].l + 1 + b[non[i] + 1].val, lst = b[non[i] + 1].val; } ans = max(ans, res); } Wtn(ans + Rdx, '\n'); } int Trd; int main() { Trd = 1; while(Trd--) init(), solve(); flush(); return 0; }