QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#83361 | #3242. 骰子旅行 | fengyuyue | AC ✓ | 159ms | 7816kb | C++14 | 3.6kb | 2023-03-01 16:50:24 | 2023-03-01 16:50:28 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define gc getchar
#define pc putchar
#define pii pair<int,int>
#define pil pair<int,long long>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define For(i,l,r) for(int i=(l);i<=(r);i++)
#define IFor(i,r,l) for(int i=(r);i>=(l);i--)
#define for_son(u) for(int e=head[u];e;e=nxt[e])
#define eps (1e-8)
#define INF 0x3f3f3f3f
using namespace std;
char aa;
namespace ljh
{
namespace IO
{
// const int SIZ=1<<20;
// char ibuf[SIZ],*p1,*p2,obuf[SIZ],*p3=obuf;
// #define gc() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,SIZ,stdin),p1==p2)?EOF:*p1++)
// void pc(const char &c)
// {
// if(p3-obuf==SIZ) fwrite(obuf,1,SIZ,stdout),p3=obuf;
// *p3++=c;
// }
int rd()
{
int x=0,f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void wr(int x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[12];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
ll ll_rd()
{
ll x=0;
int f=1;
char ch=gc();
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch)){
x=x*10+ch-'0';
ch=gc();
}
return x*f;
}
void ll_wr(ll x,char ch)
{
if(x<0) x=-x,pc('-');
static char st[22];
int top=0;
do{
st[top++]=x%10+'0',x/=10;
}while(x);
while(top) pc(st[--top]);
pc(ch);
}
}
using namespace IO;
const int N=105,M=5005,mod=998244353;
int n,s0,k;
int cnt=1,head[N],nxt[M],to[M];
int f[N][N],g[N][N][N],d[N],inv[N];
namespace tem
{
void add_edge(int u,int v){nxt[++cnt]=head[u],to[cnt]=v,head[u]=cnt;}
int qpow(int a,int b,int p)
{
a%=p;
int res=1;
while(b){
if(b&1) res=1ll*res*a%p;
a=1ll*a*a%p;
b>>=1;
}
return res;
}
int get_inv(int x){return qpow(x,mod-2,mod);}
int lowbit(int x){return x&(-x);}
void add(int &x,const int y){ x=(x+y>=mod?x+y-mod:x+y); }
// int get(int x) {return fa[x]==x?x:fa[x]=get(fa[x])};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
}
using namespace tem;
//g[s][t][i]
void main()
{
n=rd(),s0=rd(),k=rd();
inv[1]=1;
For(i,2,n) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
For(i,1,n){
int m=d[i]=rd();
while(m--){
int j=rd();
add_edge(i,j);
}
}
For(t,1,n){
For(i,0,k){
For(u,1,n){
if(u==t) g[u][t][i]=1;
else{
if(i){
for_son(u){
int v=to[e];
add(g[u][t][i],1ll*g[v][t][i-1]*inv[d[u]]%mod);
}
}
}
}
}
}
For(i,1,k){
For(u,1,n){
for_son(u){
int v=to[e];
add(f[u][i],(f[v][i-1]+1ll*v*g[v][u][i-1]%mod)%mod);
}
f[u][i]=1ll*f[u][i]*inv[d[u]]%mod;
}
}
wr(f[s0][k],'\n');
// fwrite(obuf,1,p3-obuf,stdout);
}
/*
*/
}
char bb;
int main()
{
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
// int st=clock();
ljh::main();
// int ed=clock();
// cerr<<ed-st<<"ms"<<endl;
// cerr<<(&bb-&aa)/1024/1024<<"MB"<<endl;
// fclose(stdin);
// fclose(stdout);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 159ms
memory: 7608kb
input:
100 30 100 51 8 80 45 28 2 36 19 49 74 41 24 65 3 87 7 88 10 77 91 55 92 59 69 98 84 73 83 31 40 35 23 94 62 71 46 86 12 82 5 81 33 29 9 89 22 38 44 70 14 11 60 48 15 13 48 12 23 28 42 18 27 21 43 57 96 34 2 58 73 52 70 31 76 24 82 64 39 100 75 49 56 79 14 97 92 6 33 22 3 47 8 1 32 78 4 90 45 59 44 ...
output:
882477706
result:
ok single line: '882477706'
Test #2:
score: 0
Accepted
time: 68ms
memory: 7800kb
input:
100 74 100 24 40 64 23 44 58 28 50 75 55 66 2 78 1 31 74 21 77 35 13 91 84 85 46 39 15 32 98 46 3 41 55 29 90 57 28 35 51 84 91 2 16 34 99 81 32 51 79 43 56 41 3 29 54 98 11 4 65 29 88 61 19 99 68 36 83 47 97 79 38 5 37 22 43 65 56 17 12 34 14 54 53 18 30 26 15 72 4 34 17 70 33 92 12 100 49 5 71 14 ...
output:
151569948
result:
ok single line: '151569948'
Test #3:
score: 0
Accepted
time: 29ms
memory: 7580kb
input:
100 77 100 15 61 46 33 1 2 49 77 76 89 25 84 44 100 36 29 15 25 76 2 96 46 27 3 36 91 74 62 87 44 61 73 15 66 62 3 91 73 34 30 87 22 27 74 67 4 80 96 15 66 34 5 42 55 85 90 57 80 22 67 93 92 4 30 12 92 85 90 57 55 6 54 93 75 42 64 5 12 75 16 60 7 19 64 78 6 54 81 20 63 14 8 81 39 60 71 7 78 19 63 23...
output:
392647404
result:
ok single line: '392647404'
Test #4:
score: 0
Accepted
time: 126ms
memory: 7604kb
input:
100 59 100 47 20 24 7 42 32 44 21 35 36 33 46 3 28 14 43 25 8 11 38 29 13 19 12 34 16 5 1 45 39 22 9 30 4 2 17 47 10 23 18 41 26 27 37 6 15 31 40 47 23 33 45 31 35 9 2 42 36 5 32 38 46 15 7 10 41 43 11 17 16 27 20 26 8 3 12 40 18 13 37 28 30 1 6 24 25 39 14 29 4 47 19 34 22 44 21 47 43 10 5 21 27 11...
output:
768008715
result:
ok single line: '768008715'
Test #5:
score: 0
Accepted
time: 146ms
memory: 7560kb
input:
99 92 99 50 84 24 77 41 8 60 36 90 68 42 20 32 25 7 65 47 31 40 52 27 53 14 91 51 18 94 78 96 11 29 76 10 9 74 22 6 80 4 89 46 1 44 63 49 45 17 66 43 26 81 39 32 41 92 36 91 4 22 34 88 58 15 56 86 46 43 9 84 23 11 42 35 13 21 76 30 55 87 85 26 64 78 60 53 93 7 80 90 94 45 47 4 17 19 91 37 74 27 45 8...
output:
802784090
result:
ok single line: '802784090'
Test #6:
score: 0
Accepted
time: 146ms
memory: 7668kb
input:
99 20 100 48 51 92 35 74 59 55 97 37 96 12 53 17 68 39 79 85 54 19 23 11 87 73 72 98 67 40 47 3 52 49 1 20 83 89 5 22 36 93 82 90 48 16 41 28 25 42 14 15 59 46 82 53 77 35 51 76 65 31 33 17 12 92 74 79 52 50 84 61 44 58 95 29 7 11 86 99 67 55 40 37 64 96 93 22 88 85 13 87 9 70 59 45 32 66 6 90 14 41...
output:
569176865
result:
ok single line: '569176865'
Test #7:
score: 0
Accepted
time: 119ms
memory: 7816kb
input:
100 33 100 43 81 2 43 27 87 5 49 62 35 93 47 67 38 50 20 40 61 58 78 7 92 32 26 19 55 14 24 74 15 80 56 59 28 8 84 37 54 51 12 86 70 34 22 41 41 64 82 95 16 66 25 69 53 33 71 42 21 77 18 9 99 63 57 4 13 72 46 96 60 3 23 76 90 39 29 100 68 6 85 83 75 44 30 65 11 41 12 28 14 5 98 88 67 73 15 78 26 56 ...
output:
131562182
result:
ok single line: '131562182'
Test #8:
score: 0
Accepted
time: 111ms
memory: 7604kb
input:
100 59 100 41 93 11 66 44 35 71 4 63 60 95 24 40 45 61 87 33 43 83 89 3 99 32 34 10 70 2 94 19 65 6 59 80 26 96 15 57 47 16 97 38 82 41 62 72 1 21 98 18 75 42 5 67 86 100 58 9 7 55 91 53 23 76 22 48 30 56 39 52 92 28 29 46 14 64 51 12 54 90 41 68 81 69 31 37 39 91 75 58 86 100 1 18 55 74 27 53 50 42...
output:
740370160
result:
ok single line: '740370160'
Test #9:
score: 0
Accepted
time: 37ms
memory: 7652kb
input:
100 76 100 10 95 41 64 36 42 84 58 91 2 53 14 43 93 80 7 89 97 73 39 32 68 3 57 8 23 13 34 38 20 25 83 29 19 10 69 4 81 50 60 14 66 51 49 5 77 75 56 70 13 54 79 14 59 94 17 52 98 37 27 65 61 45 78 96 44 85 9 86 21 11 28 67 11 99 92 87 82 47 46 12 17 26 1 33 13 10 50 35 81 60 20 16 29 4 83 25 69 19 1...
output:
106948111
result:
ok single line: '106948111'
Test #10:
score: 0
Accepted
time: 74ms
memory: 7528kb
input:
100 54 100 18 75 12 74 2 15 84 97 95 66 49 36 76 31 68 58 35 27 7 27 32 17 6 19 38 40 80 93 61 29 67 69 18 53 83 62 92 11 52 77 46 55 99 22 82 3 5 36 65 79 33 16 60 45 8 51 72 23 89 96 13 48 10 91 4 57 14 42 78 20 100 86 56 81 26 73 41 50 34 63 88 24 90 1 20 58 30 35 59 84 28 27 95 68 31 66 64 76 36...
output:
600809990
result:
ok single line: '600809990'
Test #11:
score: 0
Accepted
time: 7ms
memory: 7704kb
input:
100 1 100 8 2 4 9 13 19 21 68 82 6 3 6 8 11 31 100 2 12 90 6 5 7 10 15 20 73 3 14 47 49 2 23 86 1 7 1 16 2 17 79 2 18 94 6 24 26 34 38 78 80 2 37 43 3 85 87 93 2 61 62 3 28 33 60 1 32 1 30 1 27 1 22 1 81 2 44 83 2 42 50 2 25 45 1 36 2 40 46 3 41 75 91 1 84 3 29 35 63 2 55 58 2 71 99 1 31 1 66 1 88 1...
output:
678212895
result:
ok single line: '678212895'
Test #12:
score: 0
Accepted
time: 3ms
memory: 7784kb
input:
100 1 99 5 2 5 6 7 26 6 3 4 8 35 47 82 5 11 12 14 19 27 1 4 1 9 6 13 21 49 50 56 86 5 10 22 28 29 48 2 15 55 3 16 17 100 1 10 2 38 66 1 54 1 13 1 94 3 23 32 91 4 18 42 46 61 3 60 63 97 4 20 37 39 88 2 33 52 1 20 4 24 31 36 62 1 22 2 25 30 3 34 45 89 1 25 2 40 92 1 27 1 28 1 29 1 30 2 43 58 2 44 64 1...
output:
71269815
result:
ok single line: '71269815'