QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#449147#8684. Alea Iacta EstWillisWA 9510ms6812kbC++144.1kb2024-06-20 18:55:162024-06-20 18:55:17

Judging History

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

  • [2024-06-20 18:55:17]
  • 评测
  • 测评结果:WA
  • 用时:9510ms
  • 内存:6812kb
  • [2024-06-20 18:55:16]
  • 提交

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 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;
            }
        }
        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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 9510ms
memory: 6812kb

input:

6 1
ABCDEF
GHIJKL
MNOPQR
STUVWX
YZ0123
456789
AHOV29

output:

impossible

result:

wrong answer