Codeforces Round #629 (Div. 3) 1328B - K-th Beautiful String Solution



 

Problem  Link :  https://codeforces.com/problemset/problem/1328/B

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int  t;
    cin >> t;
    while ( t-- )
    {
        int n,k,i;
        cin>>n>>k;
        ll s=0, pos=0;
        for(i = 0 ; ; i++ )
        {
            s+=i;
            if(s>=k)
            {
                pos=i;
                break;
            }
        }
        int  u,v;
        u=n-pos-1;
        v=n-(k-(pos*(pos-1)/2));
        for(i = 0 ; i < n ; i++)
        {
            if(i==u||i==v)
                cout<<"b";
            else
                cout<<"a";
        }
        cout<<endl;
    }
}








No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.