QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462992 | #8836. Highway Hoax | Crying | WA | 224ms | 31556kb | C++14 | 1.6kb | 2024-07-04 11:00:01 | 2024-07-04 11:00:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5+10,mod = 998244353;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
int res = 1; a%=mod;
while(n){
if(n&1)res = 1ll*res*a%mod;
n>>=1; a = 1ll*a*a%mod;
}
return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
int n; string s;
vector<int> e[MAXN];
int f[MAXN][3],sz[MAXN],sx[MAXN];
typedef array<int,2> pr;
map<pr,int> q;
void merge(int u,int v){
int g[3] = {};
for(int x=-1;x<=1;x++)for(int y=-1;y<=1;y++)if(abs(x+y) <= 1){
add(g[x+y+1],1ll*f[u][x+1]*f[v][y+1]%mod);
}
f[u][0] = g[0],f[u][1] = g[1],f[u][2] = g[2];
}
void dfs(int u,int fa){
sz[u] = 1;
if(s[u] == 'S'){
sx[u] = 1;
f[u][0] = f[u][1] = 1;
}else{
sx[u] = 0;
f[u][1] = f[u][2] = 1;
}
for(auto v : e[u])if(v != fa){
dfs(v,u);
merge(u,v);
sz[u] += sz[v]; sx[u] += sx[v];
}
if(q.find((pr){u,fa}) == q.end()){
f[u][0] = 0;
}
if(q.find((pr){fa,u}) == q.end()){
f[u][2] = 0;
}
for(int x=-1;x<=1;x++)if(sx[u]+x < 0 || sx[u]+x > sz[u]){
f[u][x+1] = 0;
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>s; s = " "+s;
for(int i=1,u,v;i<n;i++){
cin>>u>>v;
e[u].push_back(v); e[v].push_back(u);
q[(pr){u,v}] = 1;
}
dfs(1,0);
cout<<f[1][1]<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10240kb
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: 11160kb
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: 11084kb
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: 11616kb
input:
2 FS 1 2
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 11788kb
input:
3 FFF 3 1 3 2
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 11784kb
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: 11504kb
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: 11840kb
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: 224ms
memory: 31556kb
input:
199995 FSSFFFSSSFSFFSSSFSSSSSFSFSSSFSFFSSFSFSFFFSSSFSSFSFFSFFFFSSFFSSSFFSFSFFFFFFFFFFFFFSSSFSSFFFSSSFSFSSSFFFSFFSFSSSSFSFSFSFSSFFSFSFFSFFSSFSSSFSFFSSSFFSFFFSFFSFSFSFSFSSSFSSSSFFSSFFFFFSFSSSFFSSSSSSSSFFFSFSFFSSSFSFFFFFSFFFFSSSSSSSFFFSFFSFSSSFSFSFFFFSFSSFSSFFFSSFFFSSFSFFFSSSFSFSSFFSFSFFSFFSSFSFSSSSFFF...
output:
836392907
result:
wrong answer 1st numbers differ - expected: '233157276', found: '836392907'