QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#827737 | #8947. 白兔迷宫 | 275307894a# | 12 | 7ms | 4480kb | C++14 | 3.3kb | 2024-12-23 09:25:26 | 2024-12-23 09:25:32 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=200+5,M=(1<<28)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(28382);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n,m,S,T,X[N*N],Y[N*N],Z[N*N],in[N];
ll mpow(ll x,int y=mod-2){ll ans=1;while(y) y&1&&(ans=ans*x%mod),y>>=1,x=x*x%mod;return ans;}
ll A[N][N],p[N],f[N],g[N];
void Gauss(ll *ans){
for(int i=1;i<=2*n;i++){
for(int j=i+1;j<=2*n;j++) if(A[j][i]){swap(A[i],A[j]);break;}
ll w=mpow(A[i][i]);for(int j=i;j<=2*n+1;j++) (A[i][j]*=w)%=mod;
for(int j=i+1;j<=2*n;j++){
w=mod-A[j][i];
for(int h=i;h<=2*n+1;h++) (A[j][h]+=w*A[i][h])%=mod;
}
}
for(int i=2*n;i;i--){
ans[i]=mod-A[i][2*n+1];
for(int j=i+1;j<=2*n;j++) (ans[i]+=(mod-A[i][j])*ans[j])%=mod;
ans[i]%=mod;
}
}
void Solve(){
scanf("%d%d%d%d",&n,&m,&S,&T);
for(int i=1;i<=m;i++) scanf("%d%d%d",&X[i],&Y[i],&Z[i]),in[X[i]]++;
for(int i=1;i<=n;i++) in[i]=mpow(in[i]);
Me(A,0);
for(int i=1;i<=n;i++) A[i][i]=A[i+n][i+n]=1;
A[T][2*n+1]=mod-1;
for(int i=1;i<=m;i++)if(X[i]^T){
int a=Y[i],b=X[i];
if(Z[i]){
(A[b][a]+=mod-in[b])%=mod;
(A[b+n][a+n]+=mod-in[b])%=mod;
}else{
(A[b+n][a]+=mod-in[b])%=mod;
(A[b+n][a+n]+=mod-in[b])%=mod;
}
}
Gauss(p);
gdb(p[1],p[2],p[3],p[4]);
Me(A,0);
for(int i=1;i<=n;i++) A[i][i]=A[i+n][i+n]=1;
for(int i=1;i<=m;i++)if(X[i]^T){
int a=Y[i],b=X[i];
if(Z[i]){
(A[b][a]+=mod-in[b])%=mod;(A[b][2*n+1]+=p[a]*(mod-in[b]))%=mod;
(A[b+n][a+n]+=mod-in[b])%=mod;(A[b+n][2*n+1]+=p[a+n]*(mod-in[b]))%=mod;
}else{
(A[b+n][a]+=mod-in[b])%=mod;(A[b+n][2*n+1]+=p[a]*(mod-in[b]))%=mod;
(A[b+n][a+n]+=mod-in[b])%=mod;(A[b+n][2*n+1]+=p[a+n]*(mod-in[b]))%=mod;
}
}
Gauss(f);
ll ans1=(f[S]+f[S+n])%mod;
printf("%lld ",ans1);
/*for(int i=1;i<=n;i++) A[i][i]=A[i+n][i+n]=A[i+2*n][i+2*n]=A[i+3*n][i+3*n]=1;
for(int i=1;i<=m;i++)if(X[i]^T){
int a=Y[i],b=X[i];
if(Z[i]){
for(int o:{0,2*n}){
(A[b+o][a+o]+=mod-in[b])%=mod;(A[b+o][4*n+1]+=mod-in[b])%=mod;
(A[b+o+n][a+o+n]+=mod-in[b])%=mod;(A[b+o+n][a+o]+=2*(mod-in[b]))%=mod;(A[b+o+n][4*n+1]+=mod-in[b])%=mod;
}
}else{
for(int o:{0,2*n}){
(A[b+2*n][a+o]+=mod-in[b])%=mod;
(A[b+3*n][a+o+n]+=mod-in[b])%=mod;
}
}
}
Gauss();
gdb(ans[S],ans[S+2*n]);
ll ans1=(ans[S]+ans[S+2*n])%mod,ans2=(ans[S+n]+ans[S+3*n]+(mod-ans1)*ans1)%mod;
printf("%lld %lld\n",ans1,ans2);*/
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 4348kb
input:
91 90 83 8 51 8 0 74 51 0 64 74 0 12 64 0 90 12 0 80 90 0 14 80 0 53 14 0 26 53 0 88 26 0 35 88 0 28 35 0 15 28 0 37 15 0 54 37 0 72 54 0 22 72 0 43 22 0 20 43 0 24 20 0 73 24 0 65 73 0 87 65 0 17 87 0 82 17 0 58 82 0 61 58 0 25 61 0 46 25 0 79 46 0 23 79 0 40 23 0 4 40 0 75 4 0 19 75 0 50 19 0 16 5...
output:
90
result:
points 0.0
Subtask #2:
score: 12
Acceptable Answer
Test #8:
score: 12
Acceptable Answer
time: 5ms
memory: 4352kb
input:
86 85 23 70 43 70 1 33 43 1 86 33 1 54 86 1 1 54 1 68 1 1 18 68 1 39 18 1 62 39 1 85 62 1 47 85 1 67 47 1 44 67 1 74 44 1 13 74 1 38 13 1 81 38 1 60 81 1 28 60 1 84 28 1 48 84 1 49 48 1 73 49 1 22 73 1 37 22 1 20 37 1 65 20 1 59 65 1 3 59 1 36 3 1 52 36 1 83 52 1 56 83 1 55 56 1 2 55 1 10 2 1 66 10 ...
output:
85
result:
points 0.5
Test #9:
score: 12
Acceptable Answer
time: 6ms
memory: 4460kb
input:
92 5377 22 42 53 42 1 9 53 1 81 42 1 89 42 1 65 53 1 34 89 1 35 34 1 21 35 1 23 9 1 19 53 1 46 19 1 59 21 1 58 46 1 33 89 1 27 23 1 7 35 1 15 81 1 31 81 1 79 59 1 63 81 1 83 59 1 4 35 1 75 59 1 84 9 1 20 59 1 48 53 1 60 35 1 77 35 1 64 53 1 5 83 1 28 58 1 90 65 1 39 31 1 70 65 1 74 21 1 8 27 1 36 46...
output:
791755969
result:
points 0.5
Test #10:
score: 12
Acceptable Answer
time: 3ms
memory: 4356kb
input:
89 3236 53 39 6 39 1 63 39 1 33 6 1 54 39 1 89 39 1 78 89 1 52 33 1 75 52 1 15 63 1 42 33 1 49 75 1 5 89 1 55 52 1 17 5 1 70 49 1 16 89 1 85 39 1 14 85 1 66 89 1 68 75 1 20 63 1 76 63 1 81 85 1 27 70 1 2 89 1 40 42 1 60 2 1 57 16 1 46 54 1 59 81 1 11 17 1 8 17 1 82 2 1 71 52 1 3 5 1 44 3 1 80 14 1 7...
output:
241617573
result:
points 0.5
Test #11:
score: 12
Acceptable Answer
time: 7ms
memory: 4344kb
input:
98 4882 40 87 85 87 1 53 85 1 73 87 1 93 53 1 74 53 1 9 73 1 50 73 1 65 9 1 38 9 1 67 87 1 37 9 1 64 74 1 47 67 1 26 85 1 68 9 1 31 87 1 13 37 1 44 73 1 10 93 1 91 87 1 76 13 1 41 93 1 55 87 1 24 87 1 88 68 1 25 38 1 34 93 1 2 64 1 29 93 1 69 37 1 98 31 1 20 69 1 39 13 1 72 55 1 83 37 1 77 64 1 90 8...
output:
616152076
result:
points 0.5
Test #12:
score: 12
Acceptable Answer
time: 6ms
memory: 4436kb
input:
89 2544 67 60 9 60 1 69 9 1 74 9 1 61 69 1 72 61 1 13 9 1 45 13 1 14 61 1 31 9 1 16 60 1 84 60 1 80 69 1 83 45 1 40 69 1 25 9 1 47 61 1 5 74 1 8 31 1 10 40 1 23 5 1 70 10 1 51 69 1 35 60 1 81 13 1 34 61 1 36 14 1 38 31 1 58 83 1 49 45 1 75 38 1 15 38 1 21 84 1 65 70 1 66 31 1 20 10 1 54 81 1 53 81 1...
output:
797093300
result:
points 0.5
Test #13:
score: 12
Acceptable Answer
time: 6ms
memory: 4448kb
input:
89 7921 1 17 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 17 1 1 18 1 1 19 1 1 20 1 1 21 1 1 22 1 1 23 1 1 24 1 1 25 1 1 26 1 1 27 1 1 28 1 1 29 1 1 30 1 1 31 1 1 32 1 1 33 1 1 34 1 1 35 1 1 36 1 1 37 1 1 38 1 1 39 1 1 40 1 1 41 1 1 42 1 1 ...
output:
89
result:
points 0.5
Test #14:
score: 12
Acceptable Answer
time: 6ms
memory: 4392kb
input:
90 8100 5 15 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 1 1 12 1 1 13 1 1 14 1 1 15 1 1 16 1 1 17 1 1 18 1 1 19 1 1 20 1 1 21 1 1 22 1 1 23 1 1 24 1 1 25 1 1 26 1 1 27 1 1 28 1 1 29 1 1 30 1 1 31 1 1 32 1 1 33 1 1 34 1 1 35 1 1 36 1 1 37 1 1 38 1 1 39 1 1 40 1 1 41 1 1 42 1 1 ...
output:
90
result:
points 0.5
Test #15:
score: 12
Acceptable Answer
time: 6ms
memory: 4328kb
input:
91 4288 63 78 65 78 1 74 78 1 56 74 1 16 74 1 91 65 1 30 56 1 3 65 1 40 91 1 29 65 1 48 40 1 88 91 1 57 29 1 19 40 1 21 78 1 28 56 1 13 30 1 75 65 1 11 30 1 84 74 1 7 3 1 12 13 1 85 16 1 86 85 1 67 12 1 20 57 1 17 67 1 69 20 1 24 28 1 47 17 1 27 11 1 15 69 1 41 74 1 87 16 1 89 13 1 53 28 1 76 91 1 8...
output:
114706894
result:
points 0.5
Test #16:
score: 12
Acceptable Answer
time: 5ms
memory: 4404kb
input:
86 3062 25 41 36 41 1 22 36 1 73 22 1 72 73 1 26 72 1 42 26 1 54 42 1 6 54 1 78 6 1 82 78 1 49 82 1 17 49 1 30 17 1 51 30 1 23 51 1 37 23 1 18 37 1 55 18 1 63 55 1 27 63 1 12 27 1 34 12 1 20 34 1 8 20 1 44 8 1 38 44 1 71 38 1 2 71 1 74 2 1 4 74 1 45 4 1 79 45 1 3 79 1 35 3 1 62 35 1 67 62 1 32 67 1 ...
output:
422980980
result:
points 0.5
Test #17:
score: 12
Acceptable Answer
time: 5ms
memory: 4400kb
input:
83 2712 11 64 31 64 1 30 31 1 36 64 1 80 36 1 81 31 1 33 64 1 24 30 1 74 81 1 67 24 1 38 74 1 58 81 1 41 38 1 66 36 1 63 38 1 19 67 1 72 66 1 28 72 1 43 58 1 47 66 1 14 47 1 12 28 1 55 12 1 62 30 1 21 30 1 52 12 1 11 41 1 32 24 1 37 30 1 18 11 1 5 38 1 44 43 1 20 11 1 53 66 1 40 20 1 56 64 1 4 74 1 ...
output:
817061307
result:
points 0.5
Test #18:
score: 12
Acceptable Answer
time: 5ms
memory: 4424kb
input:
84 4693 16 71 1 71 1 51 1 1 34 51 1 49 34 1 27 49 1 21 27 1 39 21 1 78 39 1 20 78 1 9 20 1 40 9 1 73 40 1 84 73 1 68 84 1 3 68 1 2 3 1 12 2 1 53 12 1 15 53 1 38 15 1 7 38 1 29 7 1 13 29 1 45 13 1 31 45 1 41 31 1 54 41 1 69 54 1 36 69 1 4 36 1 25 4 1 57 25 1 83 57 1 46 83 1 52 46 1 61 52 1 55 61 1 5 ...
output:
833057197
result:
points 0.5
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 4
Acceptable Answer
time: 5ms
memory: 4288kb
input:
90 89 77 72 38 72 1 9 38 1 20 9 1 39 20 1 61 39 1 55 61 1 46 55 1 28 46 1 56 28 1 74 56 1 35 74 1 64 35 1 27 64 1 69 27 1 79 69 1 88 79 1 31 88 1 48 31 1 57 48 1 7 57 1 85 7 1 6 85 1 63 6 1 32 63 1 34 32 1 4 34 1 67 4 1 50 67 1 11 50 1 13 11 1 71 13 1 2 71 1 45 2 1 26 45 1 43 26 1 73 43 1 44 73 1 33...
output:
89
result:
points 0.5
Test #20:
score: 0
Wrong Answer
time: 6ms
memory: 4348kb
input:
91 90 68 73 10 73 0 26 10 0 65 26 0 36 65 1 41 36 0 47 41 0 5 47 0 76 5 0 51 76 1 53 51 0 13 53 0 57 13 0 62 57 1 42 62 0 46 42 0 14 46 0 27 14 0 75 27 1 84 75 0 72 84 1 11 72 0 43 11 1 71 43 0 82 71 1 59 82 0 12 59 1 90 12 1 78 90 1 30 78 0 70 30 0 19 70 0 74 19 0 54 74 1 58 54 1 40 58 1 61 40 0 32...
output:
90
result:
points 0.0
Subtask #4:
score: 0
Wrong Answer
Test #26:
score: 0
Wrong Answer
time: 5ms
memory: 4480kb
input:
81 6493 65 20 79 20 0 15 79 0 2 20 0 12 15 0 48 15 0 77 2 0 73 15 0 74 2 0 68 79 0 54 73 0 66 54 0 69 74 0 36 12 0 25 77 0 24 48 0 53 68 0 43 15 0 58 12 0 50 73 0 16 24 0 27 68 0 65 69 0 38 24 0 11 15 1 51 68 0 32 77 0 30 50 0 3 25 0 72 12 0 8 79 0 64 24 0 17 54 0 70 66 0 31 68 0 60 17 0 21 16 0 63 ...
output:
768198821
result:
points 0.0
Subtask #5:
score: 0
Skipped
Dependency #1:
0%