QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458239 | #8836. Highway Hoax | ucup-team3678# | WA | 1062ms | 18660kb | C++14 | 1.3kb | 2024-06-29 16:24:47 | 2024-06-29 16:24:47 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 2e5 + 5, P = 998244353;
string s;
vector< pair<int, int> > G[N];
int f[3][N];
mt19937 rnd;
void dfs(int x, int fa = -1, int c = 1) {
shuffle(G[x].begin(), G[x].end(), rnd);
vector<int> tf(2000); tf[1000] = 1; if (s[x] == 'F') tf[1001] = 1; else tf[999] = 1;
for (auto [v, w] : G[x]) if (v != fa) {
dfs(v, x, w);
vector<int> tg(2000);
for (int i = 0; i < 2000; ++i) {
tg[i] = 1ll * tf[i] * f[1][v] % P;
}
if (w == 2) {
for (int i = 0; i < 1999; ++i) {
tg[i + 1] = (tg[i + 1] + 1ll * tf[i] * f[2][v]) % P;
}
} else {
for (int i = 1; i < 2000; ++i) {
tg[i - 1] = (tg[i - 1] + 1ll * tf[i] * f[0][v]) % P;
}
}
tf = tg;
}
for (int i = 0; i <= 2; ++i) if (i == 1 || i == c) {
f[i][x] = tf[999 + i];
}
}
signed main() {
int n; scanf("%d", &n); cin >> s; s = ' ' + s;
for (int i = 1; i < n; ++i) {
int x, y; scanf("%d%d", &x, &y);
G[x].push_back(make_pair(y, 2));
G[y].push_back(make_pair(x, 0));
}
dfs(1);
printf("%d\n", f[1][1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10936kb
input:
5 SFSFS 2 1 2 3 4 3 4 5
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9716kb
input:
4 SFFF 1 2 1 3 1 4
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9056kb
input:
7 SSSSFFF 1 2 3 2 4 3 4 5 4 6 2 7
output:
13
result:
ok 1 number(s): "13"
Test #4:
score: 0
Accepted
time: 2ms
memory: 9760kb
input:
2 FS 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9680kb
input:
3 FFF 3 1 3 2
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 10576kb
input:
4 FFFF 1 2 4 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 1ms
memory: 10336kb
input:
5 FFFFF 4 2 2 1 3 1 3 5
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 9136kb
input:
6 FSSSSF 5 3 2 5 1 2 2 6 4 2
output:
3
result:
ok 1 number(s): "3"
Test #9:
score: -100
Wrong Answer
time: 1062ms
memory: 18660kb
input:
199995 FSSFFFSSSFSFFSSSFSSSSSFSFSSSFSFFSSFSFSFFFSSSFSSFSFFSFFFFSSFFSSSFFSFSFFFFFFFFFFFFFSSSFSSFFFSSSFSFSSSFFFSFFSFSSSSFSFSFSFSSFFSFSFFSFFSSFSSSFSFFSSSFFSFFFSFFSFSFSFSFSSSFSSSSFFSSFFFFFSFSSSFFSSSSSSSSFFFSFSFFSSSFSFFFFFSFFFFSSSSSSSFFFSFFSFSSSFSFSFFFFSFSSFSSFFFSSFFFSSFSFFFSSSFSFSSFFSFSFFSFFSSFSFSSSSFFF...
output:
498694682
result:
wrong answer 1st numbers differ - expected: '233157276', found: '498694682'