QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524047#8684. Alea Iacta Estucup-team052AC ✓3065ms186384kbC++232.3kb2024-08-19 09:15:272024-08-19 09:15:29

Judging History

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

  • [2024-08-19 09:15:29]
  • 评测
  • 测评结果:AC
  • 用时:3065ms
  • 内存:186384kb
  • [2024-08-19 09:15:27]
  • 提交

answer

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

typedef unsigned long long ull;
typedef long double ld;

const int N = 125000;

priority_queue < pair <ld, int> > Q;
vector <int> son[N], par[N];
ld sum[N], dis[N];
int cnt[N], fix[N], cnt0[N];
int pw[10], pw6[10], id[10];
char c[10][10], foo[10], tmp[10];
int n, m;

set <ull> str;

ull hs(char *c) {
	ull ans = 0, pw = 1;
	for (int i = 1; i <= 6; i++) {
		ans += c[i] * pw;
		pw *= 300;
	}
	return ans;
}

int get(int x, int i) {
	return (x % pw[i]) / pw[i - 1];
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", c[i] + 1);
	}
	for (int i = 1; i <= m; i++) {
		scanf("%s", foo + 1);
		str.insert(hs(foo));
	}
	pw[0] = pw6[0] = 1;
	for (int i = 1; i <= n; i++) {
		pw[i] = pw[i - 1] * 7;
		pw6[i] = pw6[i - 1] * 6;
	}
	vector <int> good;
	for (int i = 0; i < pw[n]; i++) {
		int bad = 0;
		for (int j = 1; j <= n; j++) {
			int now = get(i, j);
			if (!now) {
				++bad;
			}
			tmp[j] = c[j][now];
			id[j] = j;
		}
		cnt0[i] = bad;
		if (bad) continue;
		do {
			for (int j = 1; j <= n; j++) {
				foo[j] = tmp[id[j]];
			}
			// printf("%s\n", foo + 1);
			if (str.find(hs(foo)) != str.end()) {
				good.push_back(i);
				fix[i] = 1;
				break;
			}
		} while (next_permutation(id + 1, id + n + 1));
		for (int j = 1; j < (1 << n); j++) {
			int fa = i;
			for (int k = 1; k <= n; k++) {
				if ((j >> (k - 1)) & 1) {
					fa -= get(fa, k) * pw[k - 1];
				}
			}
			son[fa].push_back(i);
			par[i].push_back(fa);
		}
	}
	if (good.empty()) {
		printf("impossible\n");
		return 0;
	}
	auto insert = [&](int id) {
		
		/*fprintf(stderr, "insert : ");
		for (int i = 1; i <= n; i++) cerr << get(id, i) << ' ';
		cerr << '\n';*/
		// fprintf(stderr, "dis = %.10Lf\n", dis[id]);
		for (auto i : par[id]) {
			sum[i] += dis[id];
			++cnt[i];
			dis[i] = (ld)sum[i] / cnt[i] + (ld)pw6[cnt0[i]] / cnt[i];
			// fprintf(stderr, "i = %d, dis[i] = %.10Lf, cnt[i] = %d\n", i, dis[i], cnt[i]);
			Q.push(make_pair(-dis[i], i));
		}
	};
	for (auto i : good) insert(i);
	while (!Q.empty()) {
		int u = Q.top().second; Q.pop();
		if (fix[u]) continue;
		fix[u] = 1;
		for (auto i : son[u]) {
			if (!fix[i]) {
				fix[i] = 1;
				dis[i] = dis[u];
				insert(i);
			}
		}
	}
	printf("%.10Lf\n", dis[0]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1372ms
memory: 176764kb

input:

6 1
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AHOV29

output:

13.9377966973

result:

ok 

Test #2:

score: 0
Accepted
time: 1531ms
memory: 174796kb

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.9377966973

result:

ok 

Test #3:

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

input:

1 1
ABCDEF
A

output:

6.0000000000

result:

ok 

Test #4:

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

input:

1 3
ABCDEF
A
E
H

output:

3.0000000000

result:

ok 

Test #5:

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

input:

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

output:

1.5000000000

result:

ok 

Test #6:

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

input:

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

output:

6.6666666667

result:

ok 

Test #7:

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

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.0909090909

result:

ok 

Test #8:

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

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.4500296208

result:

ok 

Test #9:

score: 0
Accepted
time: 6ms
memory: 4404kb

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.0709728460

result:

ok 

Test #10:

score: 0
Accepted
time: 84ms
memory: 16924kb

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.4564758929

result:

ok 

Test #11:

score: 0
Accepted
time: 1687ms
memory: 176408kb

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.5445544476

result:

ok 

Test #12:

score: 0
Accepted
time: 1817ms
memory: 176844kb

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.7651969128

result:

ok 

Test #13:

score: 0
Accepted
time: 3065ms
memory: 186384kb

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.4916963007

result:

ok 

Test #14:

score: 0
Accepted
time: 1414ms
memory: 175188kb

input:

6 2
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AGMSY4
FLRX39

output:

13.1419048352

result:

ok 

Test #15:

score: 0
Accepted
time: 984ms
memory: 174728kb

input:

6 1
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA
AAAAAA

output:

1.0000000000

result:

ok 

Test #16:

score: 0
Accepted
time: 986ms
memory: 174676kb

input:

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

output:

1.0000000000

result:

ok 

Test #17:

score: 0
Accepted
time: 1010ms
memory: 179248kb

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.0000000000

result:

ok 

Test #18:

score: 0
Accepted
time: 1440ms
memory: 175384kb

input:

6 3
ABCDEF
AGHIJK
ABCGHI
ABBDDE
FEJKFI
HIJKLM
MAAAAF
BAABFH
AAAIII

output:

10.7329355621

result:

ok 

Test #19:

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

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.0046511628

result:

ok 

Test #20:

score: 0
Accepted
time: 1886ms
memory: 177316kb

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.0000428688

result:

ok 

Test #21:

score: 0
Accepted
time: 2187ms
memory: 48592kb

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: 440ms
memory: 39244kb

input:

6 1
ABCDEG
ABCDFG
ABCEFG
ABDEFG
ACDEFG
GGGGGG
ABCDEF

output:

impossible

result:

ok 

Test #23:

score: 0
Accepted
time: 443ms
memory: 39244kb

input:

6 1
ABCDEG
ABCDFG
ABCEFG
ABDEFG
AAAGGG
AAAHHH
ABCDEF

output:

impossible

result:

ok 

Extra Test:

score: 0
Extra Test Passed