QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107456#6513. Expression 3psc233WA 3752ms13536kbC++172.2kb2023-05-21 15:55:482023-05-21 15:55:52

Judging History

你现在查看的是最新测评结果

  • [2024-02-14 13:23:19]
  • hack成功,自动添加数据
  • (/hack/531)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-21 15:55:52]
  • 评测
  • 测评结果:WA
  • 用时:3752ms
  • 内存:13536kb
  • [2023-05-21 15:55:48]
  • 提交

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-1;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);
}

详细

Test #1:

score: 100
Accepted
time: 3696ms
memory: 9736kb

input:

4
9 1 4 1
-+-

output:

46

result:

ok 1 number(s): "46"

Test #2:

score: 0
Accepted
time: 3694ms
memory: 9748kb

input:

5
1 2 3 4 5
+-+-

output:

998244313

result:

ok 1 number(s): "998244313"

Test #3:

score: -100
Wrong Answer
time: 3752ms
memory: 13536kb

input:

100000
664815434 205025136 871445392 797947979 379688564 336946672 231295524 401655676 526374414 670533644 156882283 372427821 700299596 166140732 677498490 44858761 185182210 559696133 813911251 842364231 681916958 114039865 222372111 784286397 437994571 152137641 650875922 613727135 209302742 5321...

output:

178188654

result:

wrong answer 1st numbers differ - expected: '178167352', found: '178188654'