Submission #5476205


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

map<int, int> mp;

int findPower(int i, int k)
{
    int t = i, cnt = 0;

    while (t <= k)
    {
	if (mp.find(t) != mp.end())
	{
	    cnt += mp[t];
	    break;
	}
	t *= 2;
	++cnt;
    }

    mp[i] = cnt;
    return cnt;
}

int main()
{
    int n, k;
    cin >> n >> k;

    // power of 2
    vector<int> p2(31);

    p2[0] = 1;
    for (int i=1; i<p2.size(); ++i)	p2[i] = p2[i-1] * 2;

    long double b = 0.0;
    for (int i=n; i>=1; --i)
    {
	int p = findPower(i, k);
	p = p2[p];
	b += (long double)1/p;
    }

    cout << ((long double)1/n) * b << '\n';
    return 0;
}

Submission Info

Submission Time
Task C - Dice and Coin
User haribhattt34
Language C++14 (GCC 5.4.1)
Score 0
Code Size 672 Byte
Status
Exec Time 22 ms
Memory 4992 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 01.txt, 02.txt
All 0 / 300 01.txt, 02.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt
Case Name Status Exec Time Memory
01.txt 1 ms 256 KB
02.txt 21 ms 4992 KB
11.txt 2 ms 384 KB
12.txt 22 ms 4864 KB
13.txt 1 ms 256 KB
14.txt 4 ms 768 KB
15.txt 1 ms 256 KB