QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107455 | #6513. Expression 3 | psc233 | WA | 3595ms | 9824kb | C++14 | 2.2kb | 2023-05-21 15:53:03 | 2023-05-21 15:53:06 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define cs const
using namespace std;
cs int g=3;
const int N=6e5+10;
const int mod=998244353;
const int lim=1e7;
typedef vector<int> poly;
int rev[N],inv[N],w[N],prime[N],p[N];
unordered_map<int,int>mp;
char s[N];
int n,m,len,d,x,k;
int a[N];
int mul(int x,int y){return (ll)x*y%mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int dec(int x,int y){return x-y>=0?x-y:x-y+mod;}
int ksm(int x,int y){
ll ans=1;
for (;y;y>>=1,x=mul(x,x)) if (y&1) ans=mul(ans,x);
return ans;
}
int read(){
int f=1,x=0; char c=getchar();
while (c<'0'||c>'9'){if (c=='-')f=-1;c=getchar();}
while (c>='0'&&c<='9'){x=add(mul(x,10),c-'0');c=getchar();}
return x;
}
void init(int x){
len=1,d=0;
while (len<x) {len<<=1;d++;}
for (int i=0;i<len;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(d-1));
}
inline poly NTT(poly a,int t) {
for (int i=0;i<a.size();i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int i=1;i<a.size();i<<=1) {
int s=(i<<1);
int wn=ksm(g,(mod-1)/s);
if (t==-1) wn=ksm(wn,mod-2);
for (int j=0;j<a.size();j+=s) {
int w=1;
for (int k=j;k<j+i;k++) {
int x=a[k],y=mul(a[k+i],w);
a[k]=add(x,y); a[k+i]=dec(x,y);
w=mul(w,wn);
}
}
}
if (t==-1){
ll w=ksm(a.size(),mod-2);
for (int i=0;i<a.size();i++) a[i]=mul(a[i],w);
}
return a;
}
inline poly operator *(poly a,poly b){
int n=a.size(),m=b.size();
init(n+m-1);
a.resize(len);
b.resize(len);
a=NTT(a,1); b=NTT(b,1);
for (int i=0;i<a.size();i++) a[i]=mul(a[i],b[i]);
a=NTT(a,-1);
a.resize(n+m-1);
return a;
}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
scanf("%s",s+1);
poly b,c;
for (int i=1;i<n;i++) if (s[i]=='-') b.pb(1); else b.pb(0);
int x=1;
for (int i=0;i<mod;i++){
if (x<=n) w[x]=i;
x=3ll*x%mod;
}
c.pb(dec(mod/2,w[1]));
for (int i=2;i<=n;i++) c.pb(dec(w[i-2],w[i]));
b=b*c;
int ans=a[1];
bool p=0;
for (int i=2;i<=n;i++) if (s[i-2]!='-') {
ans=add(ans,mul(a[i],ksm(g,b[i-2])));
}
for (int i=1;i<n;i++) ans=mul(ans,i);
printf("%d\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3595ms
memory: 9824kb
input:
4 9 1 4 1 -+-
output:
34
result:
wrong answer 1st numbers differ - expected: '46', found: '34'