QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116456 | #6513. Expression 3 | lvqihang2022 | TL | 1ms | 5732kb | C++14 | 1.6kb | 2023-06-29 09:23:24 | 2023-06-29 09:23:27 |
Judging History
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();
}
Details
Tip: Click on the bar to expand more detailed information
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...