1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| #include <bits/stdc++.h> using namespace std; const int N = 55,P = 998244353; inline void Plus(int &x,const int &y) { x += y;if(x >= P) x -= P;} typedef long long ll; struct Mat { int a[N][N]; Mat() { memset(a,0,sizeof a);} int * operator [](const int p) { return a[p];} Mat operator * (const Mat &rhs) const { Mat res; for(int i = 0;i < N;i++) for(int k = 0;k < N;k++) for(int j = 0;j < N;j++) Plus(res.a[i][j],1ll * this->a[i][k] * rhs.a[k][j] % P); return res; } void init() { for(int i = 0;i < N;i++) for(int j = 0;j < N;j++) a[i][j] = (i == j); } }; int n,a[N]; ll sum[N]; ll vals[N << 1]; inline int Solve(int l,int r) { int len = 0; for(int i = l + 1;i <= r;i++) { ll L = sum[i - 1] + (a[i] > 0 ? 1 : -1),R = sum[i]; if(L > R) swap(L,R); if(L - 1 >= sum[l]) vals[++len] = L - 1; vals[++len] = R; } sort(vals + 1,vals + len + 1); len = unique(vals + 1,vals + len + 1) - vals - 1; vals[0] = -0x3f3f3f3f; Mat T; for(int i = l;i <= r;i++) if(sum[i] == sum[l]) T[0][i] = 1; for(int i = 2;i <= len;i++) { Mat trs; vector<int> V; for(int j = l + 1;j <= r;j++) { ll L = sum[j - 1] + (a[j] > 0 ? 1 : -1),R = sum[j]; if(L > R) swap(L,R); if(L <= vals[i - 1] + 1 && vals[i] <= R) V.push_back(j); } for(auto id : V) for(int j = l;j < id;j++) trs[j][id] = 1; for(auto id : V) if(a[id] > 0) trs[id][id] = 1; int tim = vals[i] - vals[i - 1]; while(tim) { if(tim & 1) T = T * trs;trs = trs * trs;tim >>= 1;} } int res = 0; for(int i = l;i <= r;i++) Plus(res,T[0][i]); return res; } int main() { scanf("%d%*d",&n); for(int i = 1;i <= n;i++) scanf("%d",&a[i]); static int b[N];int tn = 0; for(int i = 1;i <= n;i++) if(a[i]) b[++tn] = a[i]; n = tn;swap(a,b); if(!n) return puts("1 1"),0; for(int i = 1;i <= n;i++) sum[i] = sum[i - 1] + a[i]; ll mx = 0; for(int i = 0;i <= n;i++) for(int j = i + 1;j <= n;j++) mx = max(mx,sum[j] - sum[i]); if(mx == 0) return printf("%d %lld\n",1,(-sum[n] + 1) % P),0; int ans = 0; for(int i = 0;i <= n;i++) { int p = -1; for(int j = i + 1;j <= n;j++) if(sum[j] - sum[i] == mx) p = j; if(~p) Plus(ans,Solve(i,p)),i = p; } printf("%lld %d\n",mx + 1,ans); return 0; }
|