QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#465192#8836. Highway Hoaxucup-team2172#WA 67ms19808kbC++141.7kb2024-07-06 18:25:042024-07-06 18:25:05

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 18:25:05]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:19808kb
  • [2024-07-06 18:25:04]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
const int base = 2;
const int INF = 998244353;

int n;
int f[maxn][5];
vector<pair<int, int> > tree[maxn];
char s[maxn];

inline void dfs(int u, int p) {
	int g[5] = {0, 0, 1, 0, 0}, dir = 0;
	for (auto e: tree[u]) {
		int v = e.first;
		if (v != p){
			dfs(v, u);
			int ng[5] = {0, 0, 0, 0, 0};
			for (int i = -2; i <= 2; ++i) if (g[i + base]) {
				for (int j = -2; j <= 2; ++j) if (f[v][j + base] && abs(i + j) <= 2)
					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] + g[-2 + base]) % INF;
		} 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: 0ms
memory: 9972kb

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: 8776kb

input:

4
SFFF
1 2
1 3
1 4

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 2ms
memory: 10420kb

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: 10160kb

input:

2
FS
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3
FFF
3 1
3 2

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 9356kb

input:

4
FFFF
1 2
4 2
2 3

output:

1

result:

ok 1 number(s): "1"

Test #7:

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

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: 9620kb

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: 67ms
memory: 19808kb

input:

199995
FSSFFFSSSFSFFSSSFSSSSSFSFSSSFSFFSSFSFSFFFSSSFSSFSFFSFFFFSSFFSSSFFSFSFFFFFFFFFFFFFSSSFSSFFFSSSFSFSSSFFFSFFSFSSSSFSFSFSFSSFFSFSFFSFFSSFSSSFSFFSSSFFSFFFSFFSFSFSFSFSSSFSSSSFFSSFFFFFSFSSSFFSSSSSSSSFFFSFSFFSSSFSFFFFFSFFFFSSSSSSSFFFSFFSFSSSFSFSFFFFSFSSFSSFFFSSFFFSSFSFFFSSSFSFSSFFSFSFFSFFSSFSFSSSSFFF...

output:

226461621

result:

wrong answer 1st numbers differ - expected: '233157276', found: '226461621'