Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma GCC optimize("Ofast")
- #pragma GCC target("tune=native")
- #pragma GCC optimize("fast-math,unroll-loops")
- #include <math.h>
- #include <algorithm>
- #include <set>
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <map>
- #include <string>
- #include <time.h>
- #include <cassert>
- #include <functional>
- #include <memory.h>
- #include <stack>
- #include <bitset>
- #include <unordered_map>
- #include <unordered_set>
- #include <random>
- #include <chrono>
- #include <complex>
- #include <fstream>
- #include <climits>
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef unsigned u;
- typedef long double ld;
- typedef vector<vector<int>> vvi;
- typedef unsigned char uc;
- typedef unsigned short us;
- typedef complex<double> cd;
- #define INF 1000000000
- #define LLINF 1000000000000000000LL
- #define EPS 1e-9l
- #define pii pair<int, int>
- const int DEBUG = 0;
- mt19937 gen((u)chrono::high_resolution_clock::now().time_since_epoch().count());
- #pragma comment(linker, "/STACK:16777216")
- const int ITER = 50000;
- ld prob[26][11];
- int a[26];
- int b[26];
- int c[26];
- ld p[10];
- ld dp[2][1 << 10];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.setf(cout.fixed);
- cout.precision(12);
- auto START_TIME = chrono::high_resolution_clock::now();
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- for (int i = 1; i <= n; i++)
- cin >> b[i];
- for (int i = 1; i <= n; i++)
- cin >> c[i];
- prob[0][1] = 1;
- for (int len = 0; len < n; len++)
- {
- for (int mult = 0; mult < 11; mult++)
- {
- for (int dig = 0; dig < 10; dig++)
- {
- int add = (a[len + 1] * dig * dig + b[len + 1] * dig + c[len + 1]) % 11;
- add = (add * mult) % 11;
- prob[len + 1][add] += prob[len][mult] / 10;
- }
- }
- }
- for (int i = 0; i < 11; i++)
- p[i % 10] += prob[n][i];
- for (int i = 0; i < 10; i++)
- {
- if (p[i] < 1e-8)
- {
- cout << -1;
- return 0;
- }
- }
- dp[0][0] = 1;
- ld res = 0;
- for (int i = 0; i + 1 < ITER; i++)
- {
- res += i * dp[i % 2][(1 << 10) - 1];
- for (int mask = 0; mask < (1 << 10) - 1; mask++)
- {
- if (dp[i % 2][mask] > 1e-10)
- {
- for (int dig = 0; dig < 10; dig++)
- {
- dp[(i + 1) % 2][mask | (1 << dig)] += dp[i % 2][mask] * p[dig];
- }
- }
- }
- fill(dp[i % 2], dp[i % 2] + (1 << 10), 0);
- }
- cout << res;
- #ifdef LOCAL
- cerr.precision(3);
- cerr << "\nWorking time: " << chrono::duration<double>(chrono::high_resolution_clock::now() - START_TIME).count() << " sec.";
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement