QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116456#6513. Expression 3lvqihang2022TL 1ms5732kbC++141.6kb2023-06-29 09:23:242023-06-29 09:23:27

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-06-29 09:23:27]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5732kb
  • [2023-06-29 09:23:24]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(A) (int)A.size() 

using std :: cin;
using std :: min; 
using std :: max; 
using std :: cout; 
using std :: vector; 

constexpr int M = 2e5 + 5, mod = 998244353; 
constexpr int INF = 0x3f3f3f3f; 

typedef long long ll; 
typedef unsigned long long ull; 
typedef double db; 

inline int read() { 
	int f = 1, s = 0; char ch = getchar(); 
	while(!isdigit(ch)) (ch == '-') && (f = -1), ch = getchar(); 
	while(isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); 
	return f * s; 
}

namespace Solver {
	int n; int a[M], sgn[M]; 
	char op[M]; 
	int fac[M], ifac[M]; 
	inline int qpow(int a, int b, int p) {
		int s = 1; 
		for(int bas = a; b; b >>= 1, bas = (ll)bas * bas % p)  
		    if(b & 1) s = (ll)s * bas % p;
		return s; 
	}
	inline void init(int n) {
		fac[0] = ifac[0] = 1; 
		for(int i = 1; i <= n; ++i) fac[i] = (ll)fac[i - 1] * i % mod; 
		ifac[n] = qpow(fac[n], mod - 2, mod); 
		for(int i = n; i; --i) ifac[i - 1] = (ll)ifac[i] * i % mod; 
	}
	inline int add(int x, int y) {return (x += y) >= mod ? x - mod : x;} 
	inline void Ad(int &x, const int &y) {if((x += y) >= mod) x -= mod;}
	inline void mian() { 
		n = read(), init(n); 
		for(int i = 1; i <= n ; ++i) a[i] = read(); 
		scanf("%s", op + 1); 
		for(int i = 1; i < n; ++i) sgn[i] = (op[i] == '+' ? 1 : mod - 1); 
		int s = a[1]; 
		for(int i = 2; i <= n; ++i) {
			int prd = 1; 
			for(int j = i - 1; j >= 1; --j) prd = (ll)prd * (sgn[j] + i - j - 1) % mod; 
			s = add(s, (ll)a[i] * ifac[i - 1] * prd % mod); 
		}
		cout << (ll)s * fac[n - 1] % mod; 
	}
} ; 


int main() 
{
	
	Solver :: mian(); 
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5440kb

input:

4
9 1 4 1
-+-

output:

46

result:

ok 1 number(s): "46"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5732kb

input:

5
1 2 3 4 5
+-+-

output:

998244313

result:

ok 1 number(s): "998244313"

Test #3:

score: -100
Time Limit Exceeded

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:


result: