QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449146 | #8684. Alea Iacta Est | Willis | AC ✓ | 9523ms | 22220kb | C++14 | 4.5kb | 2024-06-20 18:53:25 | 2024-06-20 18:53:26 |
Judging History
answer
#ifdef local
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#endif
// #pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#ifndef local
#define endl '\n'
#endif
#define pb emplace_back
#define fi first
#define se second
// #define endl '\n'
#define rep(i, l, r) for (long long i = l; i <= r; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mem(a, x) memset(a, x, sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const double pi = acos(-1);
typedef __int128_t int128;
const ll mod = 1e18;
const db eps = 1e-9;
std::mt19937_64 rng(time(0));
ll my_random(ll l, ll r)
{
uniform_int_distribution<int> range(l, r);
return range(rng);
}
void __()
{
#ifdef local
system("pause");
#endif
}
ll qp(ll a, ll b, ll mod)
{
ll ans = 1;
while (b)
{
if (b & 1)
ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
const int maxn = 2e5 + 10;
int n, m;
string dice[10];
set<string> st;
db dp[2][maxn];
int pw[maxn];
int v[10], w[10];
db tmpsum, tmpcnt;
void dfs3(int cnt, int sum, int flag)
{
if (cnt == n)
{
tmpsum += dp[(flag & 1)][sum];
tmpcnt += 1;
return;
}
else
{
if (v[cnt] != 6)
dfs3(cnt + 1, sum + pw[cnt] * v[cnt], flag);
else
for (int i = 0; i < 6; i++)
dfs3(cnt + 1, sum + pw[cnt] * i, flag);
}
}
void dfs2(int cnt, int sum, int nowsum, int flag)
{
if (cnt == n)
{
dp[flag & 1][nowsum] = min(dp[flag & 1][nowsum], dp[(flag & 1) ^ 1][sum]);
return;
}
else
{
dfs2(cnt + 1, sum + pw[cnt] * v[cnt], nowsum, flag);
dfs2(cnt + 1, sum + pw[cnt] * 6, nowsum, flag);
}
}
void dfs(int cnt, int flag)
{
if (cnt == n)
{
bool f = 1;
int sum = 0;
for (int i = 0; i < n; i++)
{
if (v[i] == 6)
f = 0;
sum += pw[i] * v[i];
}
if (f == 1)
{
string s;
for (int i = 0; i < n; i++)
{
s += dice[i][v[i]];
// cout << i << " " << v[i] << " " << dice[i][v[i]] << " " << s << endl;
}
sort(s.begin(), s.end());
if (st.find(s) != st.end())
{
// cout << "XXX " << s << " " << flag << " " << (flag & 1) << endl;
dp[flag & 1][sum] = 0;
}
else
{
dp[flag & 1][sum] = 1e10;
dfs2(0, 0, sum, flag);
}
}
else
{
tmpsum = tmpcnt = 0;
dfs3(0, 0, flag);
// cout << "XXX " << sum << " " << tmpsum << " " << tmpcnt << endl;
dp[flag & 1][sum] = tmpsum / tmpcnt + 1;
}
}
else
{
for (int i = 0; i <= 6; i++)
v[cnt] = i, dfs(cnt + 1, flag);
}
}
int main()
{
IOS;
clock_t t1 = clock();
cin >> n >> m;
pw[0] = 1;
for (int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * 7;
for (int i = 0; i < n; i++)
cin >> dice[i];
for (int i = 1; i <= m; i++)
{
string s;
cin >> s;
sort(s.begin(), s.end());
st.insert(s);
}
int iter_num = 10000;
for (int i = 0; i <= pw[n]; i++)
dp[0][i] = 1e10;
int i = 1;
while (clock() - t1 < 9.5*CLOCKS_PER_SEC)
{
dfs(0, i);
mem(dp[(i & 1) ^ 1], 0);
// for (int j = 0; j < pw[n]; j++)
// cout << dp[i & 1][j] << " ";
// cout << endl;
i += 1;
}
if (dp[(i - 1) & 1][pw[n] - 1] >= 100)
cout << "impossible" << endl;
else
cout << fixed << setprecision(20) << dp[(i - 1) & 1][pw[n] - 1] << endl;
__();
return 0;
}
/*
1 1
ABCDEF
B
*/
詳細信息
Test #1:
score: 100
Accepted
time: 9503ms
memory: 7036kb
input:
6 1 ABCDEF GHIJKL MNOPQR STUVWX YZ0123 456789 AHOV29
output:
13.93779669732732529042
result:
ok
Test #2:
score: 0
Accepted
time: 9508ms
memory: 7084kb
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.93779669732732529042
result:
ok
Test #3:
score: 0
Accepted
time: 9465ms
memory: 7724kb
input:
1 1 ABCDEF A
output:
6.00000000000000266454
result:
ok
Test #4:
score: 0
Accepted
time: 9435ms
memory: 7772kb
input:
1 3 ABCDEF A E H
output:
3.00000000000000044409
result:
ok
Test #5:
score: 0
Accepted
time: 9427ms
memory: 7472kb
input:
1 10 ABCDEF A E H 0 J Z D 9 V F
output:
1.50000000000000000000
result:
ok
Test #6:
score: 0
Accepted
time: 9443ms
memory: 7132kb
input:
2 10 QSQNZC Q5XPBR XZ PC CP ZZ RX ZN PB BB SZ SQ
output:
6.66666666666666785090
result:
ok
Test #7:
score: 0
Accepted
time: 9440ms
memory: 7400kb
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.09090909090909082835
result:
ok
Test #8:
score: 0
Accepted
time: 9483ms
memory: 7188kb
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.45002962083515196667
result:
ok
Test #9:
score: 0
Accepted
time: 9495ms
memory: 7260kb
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.07097284603834186356
result:
ok
Test #10:
score: 0
Accepted
time: 9492ms
memory: 7640kb
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.45647589293293577839
result:
ok
Test #11:
score: 0
Accepted
time: 9515ms
memory: 7028kb
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.54455444758431781338
result:
ok
Test #12:
score: 0
Accepted
time: 9510ms
memory: 7328kb
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.76519691275332402114
result:
ok
Test #13:
score: 0
Accepted
time: 9519ms
memory: 18600kb
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.49169630072443260005
result:
ok
Test #14:
score: 0
Accepted
time: 9501ms
memory: 7016kb
input:
6 2 ABCDEF GHIJKL MNOPQR STUVWX YZ0123 456789 AGMSY4 FLRX39
output:
13.14190483521903729525
result:
ok
Test #15:
score: 0
Accepted
time: 9501ms
memory: 7408kb
input:
6 1 AAAAAA AAAAAA AAAAAA AAAAAA AAAAAA AAAAAA AAAAAA
output:
1.00000000000000000000
result:
ok
Test #16:
score: 0
Accepted
time: 9501ms
memory: 7124kb
input:
6 6 000000 000000 000000 000000 000000 000000 892P2Y 000000 SVOJG3 JWE2GE VTPWRF TEJLC6
output:
1.00000000000000000000
result:
ok
Test #17:
score: 0
Accepted
time: 9502ms
memory: 14896kb
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.00000000000000000000
result:
ok
Test #18:
score: 0
Accepted
time: 9509ms
memory: 6968kb
input:
6 3 ABCDEF AGHIJK ABCGHI ABBDDE FEJKFI HIJKLM MAAAAF BAABFH AAAIII
output:
10.73293556214249910852
result:
ok
Test #19:
score: 0
Accepted
time: 9450ms
memory: 7028kb
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.00465116279069777150
result:
ok
Test #20:
score: 0
Accepted
time: 9514ms
memory: 10316kb
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.00004286877866843675
result:
ok
Test #21:
score: 0
Accepted
time: 9523ms
memory: 22220kb
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: 9517ms
memory: 7100kb
input:
6 1 ABCDEG ABCDFG ABCEFG ABDEFG ACDEFG GGGGGG ABCDEF
output:
impossible
result:
ok
Test #23:
score: 0
Accepted
time: 9504ms
memory: 6760kb
input:
6 1 ABCDEG ABCDFG ABCEFG ABDEFG AAAGGG AAAHHH ABCDEF
output:
impossible
result:
ok
Extra Test:
score: 0
Extra Test Passed