QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#486924 | #7672. Pachinko | Nahidameow | AC ✓ | 304ms | 170916kb | C++20 | 3.1kb | 2024-07-22 11:59:49 | 2024-07-22 11:59:50 |
Judging History
answer
#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
std::ifstream f(name.c_str());
return f.good();
}
namespace Math{
ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
typedef long double T;
T CX[N][60],B[N];
const int dx[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int mov[N];
T &F(int x,int y){return CX[x][y-mov[x]];}
const double eps=1e-9;
int sgn(T x){
if(fabs(x)<eps)return 0;
if(x>0)return 1;
if(x<0)return -1;
return 0;
}
bool equ(T x){return sgn(x)==0;}
void solve(){
//don't forget to open long long
int n,m;std::cin>>m>>n;
ve<int>P(4);
ve<ve<int>>I(n+1,ve<int>(m+1)),C(n+1,ve<int>(m+1));
for(auto &p:P)std::cin>>p;
int tot=0;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++){
char c;std::cin>>c;
I[i][j]=(c!='X')?tot++:-1;
if(c=='T')C[i][j]=1;
}
for(int i=0;i<tot;i++)
mov[i]=std::max(0,i-m);
auto Gauss=[&](int n,int d)->void{
for(int i=0;i<n;i++){
if(equ(F(i,i)))continue;
int u=std::min(n-1,i+d);
B[i]/=F(i,i);
for(int j=u;j>=i;j--)F(i,j)/=F(i,i);
for(int j=i+1;j<=u;j++){
B[j]-=B[i]*F(j,i);
for(int k=u;k>=i;k--)
F(j,k)-=F(i,k)*F(j,i);
}
// for(int i=0;i<tot;i++){
// for(int j=0;j<tot;j++)
// std::cout<<F(i,j)<<' ';
// std::cout<<B[i]<<'\n';
// }
// std::cout<<'\n';
}
for(int i=n-1;i>=0;i--)
for(int j=i+1;j<=std::min(n-1,i+d);j++)
B[i]-=F(i,j)*B[j];
};
T CP=0;
for(int i=0;i<m;i++)
CP+=I[0][i]!=-1;
CP=1/CP;
// for(int i=0;i<n;i++)
// for(int j=0;j<m;j++)
// std::cerr<<I[i][j]<<(j+1==m?'\n':' ');
auto check=[&](int x,int y)->bool{
return x>=0&&x<n&&y>=0&&y<m;};
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(I[i][j]!=-1){
int ID=I[i][j];
if(!i)B[ID]=CP;
F(ID,ID)=1;
T PT=100;
if(!C[i][j]){
for(int k=0;k<4;k++){
int x=i+dx[k][0],y=j+dx[k][1];
if(!check(x,y)||I[x][y]==-1)
PT-=P[k];
}
for(int k=0;k<4;k++){
int x=i+dx[k][0],y=j+dx[k][1];
if(check(x,y)&&I[x][y]!=-1)
F(I[x][y],ID)=-1.0*P[k]/PT;
}
}
}
// for(int i=0;i<tot;i++){
// for(int j=0;j<tot;j++)
// std::cout<<F(i,j)<<' ';
// std::cout<<B[i]<<'\n';
// }
Gauss(tot,m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(C[i][j])
std::cout<<std::fixed<<std::setprecision(15)<<B[I[i][j]]<<'\n';
}
int main(){
#ifndef ONLINE_JUDGE
if(!FileIfstream("IO.in")){
freopen("IO.in","w",stdout);
return 0;
}
freopen("IO.in","r",stdin);
freopen("IO.out","w",stdout);
#endif
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T=1;
//std::cin>>T;
while(T--)solve();
#ifndef ONLINE_JUDGE
std::cerr<<std::fixed<<std::setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7912kb
input:
3 2 20 20 20 40 X.X T.T
output:
0.333333333333333 0.666666666666667
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 7820kb
input:
4 5 12 33 28 27 .... .XX. .... T..T XTTX
output:
0.435853889212745 0.403753221400196 0.081202502307117 0.079190387079942
result:
ok 4 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
7 7 25 25 25 25 .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. T.T.T.T
output:
0.250000000000000 0.250000000000000 0.250000000000000 0.250000000000000
result:
ok 4 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 5844kb
input:
7 7 25 25 25 25 .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. T......
output:
1.000000000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8016kb
input:
7 7 25 25 25 25 .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. .X.X.X. T..X..T
output:
0.500000000000000 0.500000000000000
result:
ok 2 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
3 2 20 20 20 40 X.X T.T
output:
0.333333333333333 0.666666666666667
result:
ok 2 numbers
Test #7:
score: 0
Accepted
time: 290ms
memory: 169256kb
input:
20 10000 14 15 33 38 ..X...........X....X X.....X...X......... ....X.X......X..X... .X....TT..X......... ......T...........X. ...............T.X.T .............XT..... XXXX.....X...T...... ...........X.......X XX...X..X........... .X..X...X.......XX.. TXX.......X....T..T. ........X..T..TTX... ..T......
output:
0.118224885178542 0.213493463121680 0.124224597651886 0.264530430688665 0.145119997922744 0.044893538269764 0.051699616075103 0.000579982032605 0.007658920243143 0.004163886105873 0.008804183542882 0.003713719754490 0.000243066459849 0.007861030657433 0.002618670904388 0.001203869543773 0.0004575213...
result:
ok 8452 numbers
Test #8:
score: 0
Accepted
time: 296ms
memory: 170516kb
input:
20 10000 14 15 33 38 ....X....X.X........ .....X............X. .........X.......... .XX....X............ .X.......X.......... ..X..............X.. .......X.X....X..... .X...X........XX...X .X.X.X.............. ...........X........ .X..........X....... ...X.....X......X..X ..X.........X....... ..X.X....
output:
0.279302193615627 0.544301725808737 0.131761181832179 0.002796118401823 0.006182362173116 0.035656418168518
result:
ok 6 numbers
Test #9:
score: 0
Accepted
time: 304ms
memory: 170176kb
input:
20 10000 3 26 33 38 ..............X..XXX ....X....XXX......XX ....X....X.......... .X...XX....X.X...... .................... ....X...X...X.X..... .X...X......X...X... XX..X............... .X...........X...... X.........X......X.. .....X..X........... X................... X......X.....X...... ..X.......
output:
0.198843889032627 0.280636569803175 0.016712067087846 0.031693232569133 0.076215518088472 0.088919440519995 0.052230221114082 0.013342117848835 0.010022355911046 0.025943751452265 0.015809638074603 0.010403558494138 0.021609029755857 0.006298949701253 0.013180995676203 0.040446770016157 0.0237850316...
result:
ok 8553 numbers
Test #10:
score: 0
Accepted
time: 293ms
memory: 168900kb
input:
20 10000 14 15 33 38 ......X............. .X.................. .....XX............. X.........X.X....... ..X.X..XXX.........X .....X.....X.X..X... ..........X...X..... .....X.......X...... ...X..X............. .............X...... X.X......X.......... ...XX.X............. ....X..........X...X ....X....
output:
0.815901231846015 0.126515675967871 0.040677022715296 0.012844405553290 0.001893029051192 0.000693145780721 0.001155758672024 0.000131682875555 0.000065452435730 0.000062036319778 0.000051459127660 0.000003524796163 0.000004100732852 0.000001263133863 0.000000058765583 0.000000054343494 0.0000000332...
result:
ok 819 numbers
Test #11:
score: 0
Accepted
time: 288ms
memory: 170704kb
input:
20 10000 3 26 33 38 ..X.X.X....X...X.... ..X........X........ .....X.X............ ...X.....X........XX ..X..........X...... XX...X.....X........ ..X....X.......X.... ..X...X....X..X..... ...X.X.............. X.......X..X.X..X.X. X...X...X.XX..X..... .X....X............. XX..X............... X....X....
output:
0.079638233598652 0.294982751896652 0.127535807310249 0.018241986165025 0.034467321706784 0.140391766836762 0.061498569381075 0.009811545027302 0.018465292061564 0.052475943625852 0.045196300553654 0.016978045583220 0.023742953653603 0.019649175383029 0.020925586248208 0.008341759580237 0.0069938651...
result:
ok 30 numbers
Test #12:
score: 0
Accepted
time: 291ms
memory: 170916kb
input:
20 10000 14 15 33 38 X..........X........ X..X..X......XX..... ...X.........X...... .X..XX...X.X.X...... ..XX....XX.......... .......X...X....X... .X.................. ..............X...X. ..........XXX....... .X...........X...... ......X............. X....X....X.X....... .XXX..X............. .........
output:
0.887426134857897 0.086172169041139 0.023178906962549 0.002039567423679 0.000464723629817 0.000567459098281 0.000121079203358 0.000026025768341 0.000003934014944
result:
ok 9 numbers
Test #13:
score: 0
Accepted
time: 16ms
memory: 16504kb
input:
20 1000 25 25 25 25 .XXXXXXXXXXXXXXXXXXX .X...X...X...X...XTX .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X....
output:
0.999999999999923
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #14:
score: 0
Accepted
time: 15ms
memory: 14544kb
input:
20 1000 25 25 25 25 .XXXXXXXXXXXXXXXXXXX .X...X...X...X...XTX .X.X.X.X.X.X.X.X.XTX .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X.X.X.X.X.X.X.X .X.X.X....
output:
0.000000000000000 0.999999999999923
result:
ok 2 numbers