2025牛客暑期多校训练营2——Another Day of Sun(01串) · znzryb
## 思路讲解
```cpp
ll t=binpow(2,tmp,mod),tt=binpow(2,mod-2,mod),tttt=binpow(4,mod-2,mod);
ll ans=0;
A[0]=0;
FOR(i,0,N-1){
if(A[i]==0 && A[i+1]==1){
ans+=t;
ans%=mod;
}else if(A[i]==-1 && A[i+1]==-1){
ans+=t*tttt;
ans%=mod;
}else if(A[i]==0 && A[i+1]==-1){
ans+=t*tt;
ans%=mod;
}else if(A[i]==-1 && A[i+1]==1){
ans+=t*tt;
ans%=mod;
}
#ifdef LOCAL
debug(i);debug(ans);
#endif
}
```
## AC代码
[https://ac.nowcoder.com/acm/contest/view-submission?submissionId=78289781](https://ac.nowcoder.com/acm/contest/view-submission?submissionId=78289781)
::: 源代码
```cpp
// Problem: Another Day of Sun
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/108299/A
// Memory Limit: 1024 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define pb push_back
#define SZ(a) ((int) a.size())
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (int i = (a); i >= (b); --i)
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define lson(var) (var<<1)
#define rson(var) ((var<<1)+1)
#define V vector
using namespace std;
using ll = long long;using ull = unsigned long long;
using DB=double;using LD=long double;
// using i128 = __int128;
using pdd = pair<DB,DB>;using plb = pair<ll,bool>;
using pll = pair<ll,ll>;using vll=vector<ll>;
using arr3 = array<ll,3> ;using arr2 = array<ll,2>;
constexpr ll MAXN=static_cast<ll>(5e5)+10,INF=static_cast<ll>(1e17)+9; // 1e18+9也是素数
constexpr ll MAXM=(ll)5e5+10;constexpr ll MAXV=(ll)1e6+10;
constexpr ll mod=998244353;
constexpr double eps=1e-8;const double pi=acos(-1.0);
ll N,M,Q,X,K,T,lT,A[MAXN];
/*
*/
ll binpow(ll a,ll k,const ll &p){ // 迭代快速幂
ll res=1;
a%=mod; // 防止a*a溢出
while(k>0){
if((k&1)==1) res=a*res%p;
a=a*a%p;
k>>=1;
}
return res;
}
inline void __(){
cin>>N;
ll cnt=0,tmp=0;
FOR(i,1,N){
cin>>A[i];
if(A[i]==1){
++cnt;
}else if(A[i]==-1){
++tmp;
}
}
ll t=binpow(2,tmp,mod),tt=binpow(2,mod-2,mod),tttt=binpow(4,mod-2,mod);
ll ans=0;
A[0]=0;
FOR(i,0,N-1){
if(A[i]==0 && A[i+1]==1){
ans+=t;
ans%=mod;
}else if(A[i]==-1 && A[i+1]==-1){
ans+=t*tttt;
ans%=mod;
}else if(A[i]==0 && A[i+1]==-1){
ans+=t*tt;
ans%=mod;
}else if(A[i]==-1 && A[i+1]==1){
ans+=t*tt;
ans%=mod;
}
#ifdef LOCAL
debug(i);debug(ans);
#endif
}
ans%=mod;
if(ans<0) ans+=mod;
cout<<ans<<"\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//cout.tie(0);
cin>>lT;
while(lT--)
__();
return 0;
}
/*
AC
https://ac.nowcoder.com/acm/contest/view-submission?submissionId=78289781
*/
```
:::
## 心路历程(WA,TLE,MLE……)