QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749168 | #9625. 魔弹 | Zy01 | WA | 0ms | 5732kb | C++14 | 2.0kb | 2024-11-14 22:54:09 | 2024-11-14 22:54:09 |
Judging History
answer
#include<cstdio>
#define LL long long
using namespace std;
const int N = 1e5 + 10;
const int Mod = 998244353;
char a[N];
LL last[N], fl[N], fr[N], ans[N], jc[N], infact[N];
LL qwr(LL x, LL k) {
LL ans = 1;
while(k) {
if(k & 1) (ans *= x) %= Mod;
(x *= x) %= Mod;
k /= 2;
}
return ans;
}
void init(int n) {
jc[0] = 1;
infact[0] = 1;
for(int i = 1; i <= n; i++) {
jc[i] = (jc[i - 1] * i) % Mod;
infact[i] = infact[i - 1] * qwr(i, Mod - 2);
}
}
LL c(int n, int m) {
if(n < 0 || m < 0 || n < m) return 0;
if(m == 0 || m == n) return 1;
return jc[n] * infact[m] % Mod * infact[n - m] % Mod;
}
int main(){
int n;
scanf("%d", &n);
init(n);
scanf("%s", a + 1);
int lastt = 0;
for(int i = 1; i <= n; i++) {
if(a[i] == 'L'){
last[i] = lastt;
lastt = i;
}
}
lastt = n + 1;
for(int i = n; i >= 1; i--) {
if(a[i] == 'R') {
last[i] = lastt;
lastt = i;
}
}
fl[0] = 1; fl[n + 1] = 1;
fr[0] = 1; fr[n + 1] = 1;
for(int i = 1; i <= n; i++) {
if(a[i] == 'L') {
LL k = i, d = i - last[i];
fl[i] = jc[k-1] % Mod;
fl[i] += (((c(k, d) - c(k - 1, d - 1) + Mod) % Mod) * (fl[last[i]] * jc[d - 1] % Mod)) % Mod;
fl[i] %= Mod;
/// printf("%d %lld %lld %lld\n", i, k, d, fl[i]);
} else fl[i] = 0;
}
for(int i = n; i >= 1; i--) {
if(a[i] == 'R') {
LL k = n - i + 1, d = last[i] - i;
// printf("%d %lld %lld %lld\n", i, k, d, fl[i]);
fr[i] = jc[k-1] % Mod;
fr[i] += (((c(k, d) - c(k - 1, d - 1) + Mod) % Mod) * (fr[last[i]] * jc[d - 1] % Mod)) % Mod;
fr[i] %= Mod;
} else fr[i] = 0;
}
for(int i = 1; i <= n; i++) {
LL ans = 0;
if(a[i] == 'L') {
ans = (((fl[i] * fr[i + 1]) % Mod) * c(n, i)) % Mod;
} else {
ans = (((fr[i] * fl[i - 1]) % Mod) * c(n, i - 1)) % Mod;
}
printf("%lld ", ans);
// printf("%lld %lld %lld %lld %lld\n", last[i], ans, fl[i], fr[i], c(n, i));
}
puts("");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
input:
2 RL
output:
1 1
result:
ok single line: '1 1 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
4 LLRR
output:
0 24 24 0
result:
ok single line: '0 24 24 0 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
4 RLRL
output:
9 6 6 9
result:
ok single line: '9 6 6 9 '
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 5732kb
input:
10 LRLRLLRRRR
output:
885727009 885727009 -120974945 -120974945 0 560052622 560052622 0 0 0
result:
wrong answer 1st lines differ - expected: '1088640 1088640 604800 604800 0 1935360 1935360 0 0 0', found: '885727009 885727009 -120974945...45 0 560052622 560052622 0 0 0 '