Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define F first
- #define S second
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define SELO ""
- #define openfiles ifstream cin("input" SELO ".txt"); ofstream cout("output" SELO ".txt");
- #define faster ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
- #define all(x) x.begin(), x.end()
- using namespace std;
- int main()
- {
- openfiles
- string a;
- ll n;
- cin >> a >> n;
- vector <ld> dp2(n + 1), dp5(n + 1);
- ll sum = 0;
- ld cnt5 = 0, cnt2 = 0;
- for(int i = 0; i < a.size(); i++)
- {
- sum = (a[i] - '0' + sum) % 3;
- if((a[i] - '0') % 2 == 0)
- cnt2++;
- if(a[i] == '5')
- cnt5++;
- }
- if(a.back() == '5')
- dp5[0] = 1;
- if((a.back() - '0') % 2 == 0 && sum == 0)
- dp2[0] = 1;
- ld n1 = a.size();
- for(int i = 1; i <= n; i++)
- {
- dp5[i] = max(dp5[i - 1] * ((n1 - 2) / n1 + 2 / n1 * (cnt5 - 1) / (n1 - 1)) + (1 - dp5[i - 1]) * (2.0 / n1 * (cnt5) / (n1 - 1)), dp5[i]);
- }
- if(sum == 0)
- for(int i = 1; i <= n; i++)
- {
- dp2[i] = max(dp2[i - 1] * ((n1 - 2) / n1 + 2 / n1 * (cnt2 - 1) / (n1 - 1)) + (1 - dp2[i - 1]) * (2.0 / n1 * (cnt2) / (n1 - 1)), dp2[i]);
- }
- cout << fixed << setprecision(20) << dp2[n] + dp5[n];
- }
Advertisement
Add Comment
Please, Sign In to add comment