QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#465182 | #8836. Highway Hoax | ucup-team2172# | WA | 44ms | 18328kb | C++14 | 1.7kb | 2024-07-06 18:17:03 | 2024-07-06 18:17:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int base = 1;
const int INF = 998244353;
int n;
int f[maxn][3];
vector<pair<int, int> > tree[maxn];
char s[maxn];
inline void dfs(int u, int p) {
int g[3] = {0, 1, 0}, dir = 0;
for (auto e: tree[u]) {
int v = e.first;
if (v != p){
dfs(v, u);
int ng[3] = {0, 0, 0};
for (int i = -1; i <= 1; ++i) if (g[i + base]) {
for (int j = -1; j <= 1; ++j) if (f[v][j + base] && abs(i + j) <= 1)
ng[i + j + base] = (ng[i + j + base] + 1ll * g[i + base] * f[v][j + base]) % INF;
}
memcpy(g, ng, sizeof(ng));
} else dir = e.second;
}
int have = (s[u] == 'S');
if (dir == 0) {
if (have) f[u][0 + base] = (g[0 + base] + g[-1 + base]) % INF;
else f[u][0 + base] = (g[0 + base] + g[1 + base]) % INF;
}
else if (dir == -1) {
if (have) {
f[u][0 + base] = (g[0 + base] + g[-1 + base]) % INF;
f[u][-1 + base] = g[-1 + base];
} else {
f[u][-1 + base] = (g[-1 + base] + g[0 + base]) % INF;
f[u][0 + base] = g[0 + base];
}
}
else {
if (have) {
f[u][1 + base] = (g[0 + base] + g[1 + base]) % INF;
f[u][0 + base] = (g[0 + base] + g[-1 + base]) % INF;
}
else {
f[u][0 + base] = (g[0 + base] + g[1 + base]) % INF;
f[u][1 + base] = g[1 + base];
}
}
// printf("u = %d f = (%d %d %d)\n", u, f[u][-1 + base], f[u][0 + base], f[u][1 + base]);
}
int main(){
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i < n; ++i) {
int u, v; scanf("%d%d", &u, &v);
--u, --v;
tree[u].push_back(make_pair(v, 1));
tree[v].push_back(make_pair(u, -1));
}
dfs(0, -1);
printf("%d\n", f[0][0 + base]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 10092kb
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: 9596kb
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: 9344kb
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: 1ms
memory: 8812kb
input:
2 FS 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 10420kb
input:
3 FFF 3 1 3 2
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 8956kb
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: 10020kb
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: 9080kb
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: 44ms
memory: 18328kb
input:
199995 FSSFFFSSSFSFFSSSFSSSSSFSFSSSFSFFSSFSFSFFFSSSFSSFSFFSFFFFSSFFSSSFFSFSFFFFFFFFFFFFFSSSFSSFFFSSSFSFSSSFFFSFFSFSSSSFSFSFSFSSFFSFSFFSFFSSFSSSFSFFSSSFFSFFFSFFSFSFSFSFSSSFSSSSFFSSFFFFFSFSSSFFSSSSSSSSFFFSFSFFSSSFSFFFFFSFFFFSSSSSSSFFFSFFSFSSSFSFSFFFFSFSSFSSFFFSSFFFSSFSFFFSSSFSFSSFFSFSFFSFFSSFSFSSSSFFF...
output:
47859013
result:
wrong answer 1st numbers differ - expected: '233157276', found: '47859013'