QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#805659#8684. Alea Iacta Estucup-team173#AC ✓4101ms42272kbC++203.0kb2024-12-08 17:50:262024-12-08 17:50:27

Judging History

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

  • [2024-12-08 17:50:27]
  • 评测
  • 测评结果:AC
  • 用时:4101ms
  • 内存:42272kb
  • [2024-12-08 17:50:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using db = double;
mt19937_64 rng(time(0));
ll get(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}
constexpr db eps = 1e-9;

void solve() {
    int d, w;
    cin >> d >> w;
    vector<string> roll(d);
    set<string> ws;
    int S = 1 << (3 * d);
    vector G(S, vector<int>());
    for(int i = 0; i < d; i++) {
        cin >> roll[i];
    }
    for(int i = 0; i < w; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ws.insert(s);
    }
    int flg = 0;
    vector<int> states;
    vector<db> f(S), g(S);
    vector<int> count(S), pw6(d + 1);
    pw6[0] = 1;
    for(int i = 1; i <= d; i++) pw6[i] = pw6[i - 1] * 6;
    for(int i = 1; i < (S); i++) {
        count[i] = count[i >> 3] + ((i & 7) != 0);
    }
    auto dfs = [&](auto self, int x, string t, int cur) {
        if(x == d) {
            sort(t.begin(), t.end());
            states.push_back(cur);
            if(ws.count(t)) flg = 1;
            else f[cur] = get(9e8, 1e9);
            for(int i = 1; i < (1 << d); i++) {
                int to = cur;
                for(int j = 0; j < d; j++) if(i >> j & 1) {
                    to &= ~(7 << (3 * j));
                }
                G[cur].push_back(to);
            }
            return;
        }
        for(int i = 1; i <= 6; i++) {
            self(self, x + 1, t + roll[x][i - 1], cur | (i << (3 * x)));
        }
    };
    dfs(dfs, 0, "", 0);
    // cerr << "ok\n";
    if(!flg) {
        cout << "impossible\n";
        return;
    }
    double delta = 0;
    // for(auto st : states) {
    //     // ans += f[st];
    //     // cerr << f[st] << '\n';
    //     cerr << st << ": ";
    //     for(auto nst : G[st]) {
    //         cerr << nst << ' ';
    //     }
    //     cerr << '\n';
    // }
    // // return;
    do {
        g.assign(S, 0);
        for(auto st : states) {
            for(auto nst : G[st]) {
                g[nst] += f[st];
            }
        }
        for(int i = 0; i < S; i++) {
            assert(count[i] <= d && count[i] >= 0);
            g[i] /= pw6[d - count[i]];
            // cerr << g[i] << '\n';
        }
        delta = 0;
        for(auto st : states) if(f[st] >= eps) {
            double nxt = 1e9;
            for(auto nst : G[st]) {
                nxt = fmin(nxt, g[nst]);
            }
            nxt += 1;
            // cerr << nxt << ' ' << fabs(nxt - f[st]) << '\n';
            delta += fabs(nxt - f[st]);
            f[st] = nxt;
        }
        // cerr << "-----------------\n";
        // break;
    } while(delta >= eps);
    db ans = 0;
    for(auto st : states) {
        ans += f[st];
        // cerr << f[st] << '\n';
    }
    cout << setprecision(20) << ans / pw6[d] + 1 << '\n';
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4078ms
memory: 27136kb

input:

6 1
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AHOV29

output:

13.937796697327334172

result:

ok 

Test #2:

score: 0
Accepted
time: 4101ms
memory: 27092kb

input:

6 720
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AHOV29
AHOV92
AHO2V9
AHO29V
AHO9V2
AHO92V
AHVO29
AHVO92
AHV2O9
AHV29O
AHV9O2
AHV92O
AH2OV9
AH2O9V
AH2VO9
AH2V9O
AH29OV
AH29VO
AH9OV2
AH9O2V
AH9VO2
AH9V2O
AH92OV
AH92VO
AOHV29
AOHV92
AOH2V9
AOH29V
AOH9V2
AOH92V
AOVH29
AOVH92
AOV2H9
AOV29H
AOV9H2
AOV92H
...

output:

13.937796697327334172

result:

ok 

Test #3:

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

input:

1 1
ABCDEF
A

output:

6.0000000006979066214

result:

ok 

Test #4:

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

input:

1 3
ABCDEF
A
E
H

output:

3.0000000003056901399

result:

ok 

Test #5:

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

input:

1 10
ABCDEF
A
E
H
0
J
Z
D
9
V
F

output:

1.5000000000779896148

result:

ok 

Test #6:

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

input:

2 10
QSQNZC
Q5XPBR
XZ
PC
CP
ZZ
RX
ZN
PB
BB
SZ
SQ

output:

6.6666666667942564573

result:

ok 

Test #7:

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

input:

2 100
SOJRTZ
GVCDFJ
FJ
ST
TJ
JR
JZ
TC
VO
ZF
OD
TO
DR
VS
BM
RF
GJ
RJ
ZC
TD
TG
RT
FV
GF
RS
GV
OR
VF
CT
DD
RR
CR
ZG
SG
JG
TT
GZ
DS
DC
VT
CF
0V
FR
ZJ
OF
CS
RD
ZZ
FC
FZ
FG
TV
GR
VD
ZT
RZ
CJ
OS
CG
GT
OZ
GD
GG
SZ
VC
JF
DG
TS
GS
RO
JD
SV
TR
VP
ZO
VR
MC
OC
FS
VG
DZ
9T
OO
DJ
FF
VV
JO
FT
CE
JT
CC
GC
DT
VJ
OJ
O...

output:

1.0909090909093395183

result:

ok 

Test #8:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

3 100
P5PHSE
UFY8PT
41RXDF
HFE
4PD
RHT
RHU
FF5
4S1
485
HD4
1PX
S1F
PEP
TFD
SE4
PH8
5XP
8S8
PET
FHY
F5R
14S
R5F
U1R
X1R
TTP
P1U
ST8
DPU
4Y5
R18
H1T
E8R
XPT
8UF
EFF
D81
4PH
FX4
H1Y
H1P
XPH
YXR
HH8
DTE
XDY
4DX
448
R4E
E88
41H
FHH
4D1
HTY
RTT
U8X
PPX
YT4
HTX
HXS
PTX
E5Y
F5E
DUF
PDH
YF5
XR4
FY1
REE
P8R
H...

output:

3.4500296208423599786

result:

ok 

Test #9:

score: 0
Accepted
time: 16ms
memory: 4240kb

input:

4 100
5PEEC4
ULCP5Z
CL6WVE
3GYXPF
VELC
3Y5L
UCC6
UZCL
YG4C
UFFX
GPWQ
P3LG
GXXY
G6PE
PULL
5PLY
CCXF
XE4F
LPZG
XVLW
XXCG
XGZW
GG5F
UCPF
GF5G
P4C4
WLUZ
LU35
X464
WXYW
ULVE
XWPL
WZLG
YC5Z
4U3Y
F4GG
VUXZ
XPC4
VW64
4FCE
3XFW
CECL
XW6P
66YP
XVX6
C5XX
E4WW
3WEY
L4YZ
XLXY
3GYZ
4XZP
6664
P53F
CFPC
4E3W
XWUV
U...

output:

7.0709728460419469798

result:

ok 

Test #10:

score: 0
Accepted
time: 276ms
memory: 6072kb

input:

5 100
7ID9X8
WAK3L3
V2UN9O
S02TLK
Q9WEYE
QUS9A
K78XU
L9IAU
202SD
7OQWT
XUVSE
IIOY2
X0VLY
QEAF0
DI8OX
7WKWQ
0OQK0
U79WO
QNWLG
DWK9N
D8ALX
9XNUX
0UN3O
UY9KY
S3QQV
YS2QP
S87O2
QNETA
30L92
2TNDN
IKN2O
TEN8E
T90NL
WAEYI
V9D93
YYIYT
A392S
D3VQT
K0VLT
QOV98
WT22Q
OUONO
0VVTW
LLWEO
UE0AT
7WYI8
IA7IK
L0N38
2...

output:

9.4564758929334278292

result:

ok 

Test #11:

score: 0
Accepted
time: 4036ms
memory: 27396kb

input:

6 100
TXNF5K
4IVTBW
JEO0YY
9H44AB
THU0SD
RUIG0Y
5DHXET
FTSD0O
KTA5H5
RS4FVW
IO4U95
S44E4E
XKJ545
WGUN0S
INFR5R
9VX54H
UOYVGS
RSKBNB
45NSNW
FRW0OB
JX5SUW
GWR4NX
GABV4V
J5DJU9
5TBBJE
TNRO5J
NVBW0B
BH5OWH
FOO4EI
XAY5GX
KJSBVV
KRH9KN
4H90J9
TOW5DH
O5USJ5
TI555V
YJXEHV
ESJHSH
IB9ARD
VYHN0I
X59RJN
TEUUAS
...

output:

11.544554447584317813

result:

ok 

Test #12:

score: 0
Accepted
time: 3171ms
memory: 27456kb

input:

6 1000
BP7BFL
Q8L6GD
01GQ5A
7971QB
1ZEEK9
VJRXE9
90Q6EV
5ZL61E
6DFRBJ
X1FKXA
L6GKDF
77ZXJ7
X0ABD7
V7VBA8
RP1KE7
F67EAL
DK7179
8XDQP7
9E0VF7
0D7D9F
EP0LVK
1QQLBF
L7ZKZZ
877DBE
KKDP5V
VBVJKD
F0R6QB
QZF1ZR
ADZ1D6
B17A7E
PLLPLG
KEV569
G9VBKE
V68XRR
QBDEPF
EVPEAL
PRPJ7L
BA7XBX
LG6JER
5VE9R7
GF59RP
XQ9P5J...

output:

7.7651969127533657655

result:

ok 

Test #13:

score: 0
Accepted
time: 428ms
memory: 38212kb

input:

6 200000
SNVSEG
RKK4SB
O4240G
71JZVE
7D3UBY
521U0W
2RSJ3Z
K3N5JN
OWS0WW
UEUZ71
GS4BVZ
JKG3E5
5W3RO1
E0O72Z
YSTB34
235UGY
KNV4R4
US1RDV
3SV4J2
OV3UBG
SGE24V
K0V0VN
1SDN54
4NN17J
VR52S1
1DNW12
DB0JGU
73UN0O
7RE1ZS
Y5JYW4
GN7GYS
12K71N
YE27KR
OWURRD
R7SNS0
S57511
DDBRNB
ZYV7OK
Z7SRVE
WOY5BN
12DJWV
SZR4...

output:

1.491696300724437263

result:

ok 

Test #14:

score: 0
Accepted
time: 3906ms
memory: 27292kb

input:

6 2
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AGMSY4
FLRX39

output:

13.141904835219044401

result:

ok 

Test #15:

score: 0
Accepted
time: 31ms
memory: 27388kb

input:

6 1
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA

output:

1

result:

ok 

Test #16:

score: 0
Accepted
time: 36ms
memory: 27384kb

input:

6 6
000000
000000
000000
000000
000000
000000
892P2Y
000000
SVOJG3
JWE2GE
VTPWRF
TEJLC6

output:

1

result:

ok 

Test #17:

score: 0
Accepted
time: 76ms
memory: 34992kb

input:

6 100000
000000
000000
000000
000000
000000
000000
BK54RD
Y58FK5
YSL2H4
T6ILVG
WQA18V
BHYR2X
DHJYD6
H14OYD
4XAHU7
KL8E52
MLDKHN
JECPCR
EYB5CI
J1A90H
AHPNC5
0D8X7L
HZH3PR
7YWGIN
HEVSCL
JKCOY2
JMT3VM
487PFY
4EQBAV
PY6G7R
U0V39V
A8ZCWH
Q9YN2E
2A11TO
FYICKF
0M3VXT
A6WHYT
PERG7W
BIPJLF
55S1NY
15HKCZ
41U4...

output:

1

result:

ok 

Test #18:

score: 0
Accepted
time: 3686ms
memory: 27372kb

input:

6 3
ABCDEF
AGHIJK
ABCGHI
ABBDDE
FEJKFI
HIJKLM
MAAAAF
BAABFH
AAAIII

output:

10.732935562142525754

result:

ok 

Test #19:

score: 0
Accepted
time: 1ms
memory: 3952kb

input:

3 197
82RHZP
PLT71M
BVPA7L
2AP
LZT
RBL
LPZ
2L1
7HB
18V
MB8
MPB
P77
HLA
LRL
M2L
78P
RP7
T8B
VP2
LHB
1BH
77Z
PBT
P2T
LVP
1PR
TVH
PLA
77R
7PV
LLH
A1R
7AR
TP8
12A
HP7
RVP
M2B
L2P
2VT
PZB
AT2
MPL
TR7
MRB
RAT
8AT
T2L
ZVM
PTR
MA8
TPH
BTH
B2L
MZB
A8L
Z7B
HA1
PTZ
AHP
2B1
2BT
TAZ
V21
VL8
A27
MPV
MAP
PMH
RAP
7...

output:

1.0046511627907017683

result:

ok 

Test #20:

score: 0
Accepted
time: 80ms
memory: 29992kb

input:

6 33244
LUWJKL
YRDQ3C
DULT8Y
OFDHGS
YIQO80
79IVAR
I8QSJC
FQLVJC
OUFRWA
YGI7JT
O9RL8J
YF8WTA
T7Q0UD
8VLLCS
398YWG
0DYL9Q
GYRYOJ
YDYYRK
RIO8K3
LGICUI
DDIDKO
OLODQV
83U7UF
ADUJO0
WRV0HU
QRJT0F
GUTQVC
JIYOTR
TRJDQR
9O3OLL
7DCTL0
YRYUOK
HQDUDA
T3JFRQ
J0YGUR
QSRU3U
ROOUYJ
OU7UO3
8VUCIS
IDDJ80
DHTLVI
UDQ9C...

output:

1.0000428687786684367

result:

ok 

Test #21:

score: 0
Accepted
time: 142ms
memory: 42272kb

input:

6 200000
LAJVID
F69ILK
YKO73F
KFVICF
AH34WW
II4C37
4RCSF1
T6OAXD
9K20HM
6Z1UHH
4XXOJ9
TSU9J9
4FJ253
O2AFAA
TE38FB
4U9D59
ZV6IRQ
A921GF
06U96J
THYLMG
PXNVRO
P7HY2Q
VUR4JU
9UXGTH
7QG48P
LK41I5
GH0UCE
QFASQW
2PL0LX
SRBOCK
T3H6AI
Y9FC8A
NNSKP4
MHMTCK
5A9G26
0XZ9C5
7IBMY7
O7Y7G5
DOBZBC
5L03QV
Q2ZUO0
QSK4...

output:

impossible

result:

ok 

Test #22:

score: 0
Accepted
time: 25ms
memory: 27084kb

input:

6 1
ABCDEG
ABCDFG
ABCEFG
ABDEFG
ACDEFG
GGGGGG
ABCDEF

output:

impossible

result:

ok 

Test #23:

score: 0
Accepted
time: 27ms
memory: 27368kb

input:

6 1
ABCDEG
ABCDFG
ABCEFG
ABDEFG
AAAGGG
AAAHHH
ABCDEF

output:

impossible

result:

ok 

Extra Test:

score: 0
Extra Test Passed