Submission #994852


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MAX = 300006;

ll n, a;
ll s[MAX + 5];

ll go(ll b)
{
    ll time = 0;
    ll speed = b;
    ll ans = n;
    while (speed <= n)
    {
        ans = min(ans, time + (n + speed - 1) / speed);
        speed *= 2;
        time += a + 2;
    }
    return ans;
}

inline ll f(ll n)
{
    return min({n, go(2 * a), go(2 * a + 1), go(2 * a + 2), go(2 * a + 3), go(a)});
}

inline ll g(ll n)
{
    pair<ll, int> ans = {n, 1};
    for (int i = 1; i <= n; i++) ans = min(ans, {s[i] + (n + i - 1) / i, i});
    if (n == 25) cout << ans.se << endl;
    return ans.fi;
}

inline ll g2(ll n)
{
    ll ans = n;
    for (int i = 1; i <= MAX; i++) ans = min(ans, s[i] + go(i));
    return ans;
}

int main()
{
    cin >> n >> a;
//     cout << f(n) << endl;
    
    s[1] = 0;
    for (int i = 2; i <= MAX; i++)
    {
        s[i] = i + a;
        for (int j = 1; j * j <= i; j++) if (i % j == 0)
        {
            s[i] = min(s[i], (i + j - 1) / j + s[j] + a);
            if (j > 1) s[i] = min(s[i], (i + (i / j) - 1) / (i / j) + s[i / j] + a);
        }
//         cout << i << ' ' << s[i] << endl;
    }
    cout << g2(n) << endl;
    
//     for (n = 1; n <= 1000; n++) if (g2(n) != g(n))
//     {
//         cout << n << ' ' << g2(n) << ' ' << g(n) << endl;
//     }
    
    return 0;
}

Submission Info

Submission Time
Task A - Where's Snuke?
User KAN
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1701 Byte
Status WA
Exec Time 429 ms
Memory 2560 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 100
Status
WA × 2
WA × 9
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt
Case Name Status Exec Time Memory
01-01.txt WA 429 ms 2560 KB
01-02.txt WA 428 ms 2560 KB
01-03.txt WA 428 ms 2560 KB
01-04.txt WA 429 ms 2560 KB
01-05.txt WA 429 ms 2560 KB
01-06.txt WA 428 ms 2560 KB
01-07.txt WA 428 ms 2560 KB
sample-01.txt WA 429 ms 2560 KB
sample-02.txt WA 429 ms 2560 KB