QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449145 | #8684. Alea Iacta Est | Willis | WA | 27ms | 6176kb | C++14 | 4.5kb | 2024-06-20 18:52:38 | 2024-06-20 18:52:38 |
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 < 9500)
{
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: 0
Wrong Answer
time: 27ms
memory: 6176kb
input:
6 1 ABCDEF GHIJKL MNOPQR STUVWX YZ0123 456789 AHOV29
output:
impossible
result:
wrong answer