QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124719 | #6513. Expression 3 | psc233 | WA | 152ms | 49996kb | C++17 | 2.7kb | 2023-07-15 14:31:01 | 2023-07-15 14:31:05 |
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=1e6;
typedef vector<int> poly;
int rev[N],inv[N],w[N];
unordered_map<int,int>mp;
char s[N];
int n,m,len,d,x,k;
int a[N];
struct FastMod {
typedef unsigned long long ULL;
typedef __uint128_t LLL;
ULL b, m;
void init(ULL b) { this->b = b, m = ULL((LLL(1) << 64) / b); }
ULL operator()(ULL a){
ULL q = (ULL)((LLL(m) * a) >> 64);
ULL r = a - q * b;
return r >= b ? r - b : r;
}
} M;
inline int mul(int a, int b) { return M(1ull * a * b); }
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;
}
const int sq=ksm(ksm(g,lim),mod-2);
int get(int x){
if (x==0) return 0;
for (int i=0,t=1;;t=mul(t,sq),i++){
if (mp[mul(t,x)]){
return i*lim+mp[mul(t,x)]-1;
}
}
}
int main(){
scanf("%d",&n);
M.init(mod);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
for (int i=0,t=1;i<lim;i++,t=mul(t,g)){
mp[t]=i+1;
}
scanf("%s",s+1);
poly b,c;
for (int i=1;i<n;i++) if (s[i]=='-') b.pb(1); else b.pb(0);
for (int i=1;i<=n;i++) w[i]=get(i);
c.pb(dec(get(mod-1),w[1]));
for (int i=2;i<=n;i++) c.pb(dec(get((i-2+mod)%mod),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: 152ms
memory: 49996kb
input:
4 9 1 4 1 -+-
output:
375176406
result:
wrong answer 1st numbers differ - expected: '46', found: '375176406'