/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 164ms 704.0 KiB
#3 Accepted 193ms 704.0 KiB
#4 Accepted 191ms 744.0 KiB

Code

#include <bits/stdc++.h>
#define int long long
using namespace std;
/*
        OBSERVATIONS:

    so root k method gives TLE

    maybe some BS or greedy way to find this..

    BS can be whether  b occurs at this point

    or not..

    if i think k as a dash ..


    so one thing i found is that root 2*k

    groups are def there before any k ..

    there is +-n diff this is approximation..

    so for small values like






*/
int isqrt(int x)
{
    int r = sqrtl(x);
    while ((r + 1) * (r + 1) <= x)
        r++;
    while (r * r > x)
        r--;
    return r;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int k;
        cin >> k;

        int curr = 0;
        bool a_turn = true;
        bool is_a = true;
        int group_before = isqrt(2 * k);
        group_before -= 2;
        group_before = max(group_before, 0LL);

        int as = group_before + 1;
        curr += (group_before) * (group_before + 1) / 2;
        if (curr)
            curr += group_before;

        while (true)
        {
            if (a_turn)
            {
                a_turn = false;
                curr += as;
                as++;
                if (curr >= k)
                {
                    break;
                }
            }
            else
            {
                curr++;
                if (curr == k)
                {
                    is_a = false;
                    break;
                }
                a_turn = 1;
            }
        }
        if (is_a)
            cout << 'a' << endl;
        else
            cout << 'b' << endl;
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1223 C. Infinity Sequence
Contest
Happy New Year 2026
Language
C++17 (G++ 13.2.0)
Submit At
2026-01-06 15:51:01
Judged At
2026-01-06 15:51:01
Judged By
Score
100
Total Time
193ms
Peak Memory
744.0 KiB