1913A - Rating Increase - CodeForces Solution


implementation

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fr(i, n) for (ll i = 0; i < n; i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
ll const N = 1e5;

bool isPrime(ll n)
{

    if (n <= 1)
        return false;

    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
ll fact(ll n)
{
    if (n == 0)
        return 1;
    return n * fact(n - 1);
}
int divCount(int n)
{
    // sieve method for prime calculation
    bool hash[n + 1];
    memset(hash, true, sizeof(hash));
    for (int p = 2; p * p < n; p++)
        if (hash[p] == true)
            for (int i = p * 2; i < n; i += p)
                hash[i] = false;

    // Traversing through all prime numbers
    int total = 1;
    for (int p = 2; p <= n; p++)
    {
        if (hash[p])
        {

            int count = 0;
            if (n % p == 0)
            {
                while (n % p == 0)
                {
                    n = n / p;
                    count++;
                }
                total = total * (count + 1);
            }
        }
    }
    return total;
}

vector<ll> prfact(ll n, vector<ll> v)
{

    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            v.push_back(i);
        v.push_back(n / i);
    }
    return v;
}

ll countSetBits(ll n)
{
    ll count = 0;
    while (n)
    {
        count += n & 1;
        n >>= 1;
    }
    return count;
}

ll setBit(ll n, ll k)
{
    return ((1 << k) | n);
}

ll power(ll x, ll y, ll p)
{

    ll res = 1;
    while (y > 0)
    {
        if (y % 2 == 1)
            res = (res * x);
        y = y >> 1;
        x = (x * x);
    }
    return res % p;
}
int msbPos(ll n)
{
    int msb_p = -1;
    while (n)
    {
        n = n >> 1;
        msb_p++;
    }
    return msb_p;
}

ll andinrange(ll a, ll b)
{

    int shiftcount = 0;
    while (a != b and a > 0)
    {
        shiftcount++;
        a = a >> 1;
        b = b >> 1;
    }
    return (a << shiftcount);
}
ll sumDigits(ll no)
{
    if (no == 0)
    {
        return 0;
    }

    return (no % 10) + sumDigits(no / 10);
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

// Function to find gcd of array of
// numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if (result == 1)
        {
            return 1;
        }
    }
    return result;
}
bool isSubstring(string s1, string s2)
{
    int M = s1.length();
    int N = s2.length();

    /* A loop to slide pat[] one by one */
    for (int i = 0; i <= N - M; i++)
    {
        int j;

        /* For current index i, check for
 pattern match */
        for (j = 0; j < M; j++)
            if (s2[i + j] != s1[j])
                break;

        if (j == M)
            return 1;
    }

    return 0;
}
bool isPalindrome(string S)
{
    // Stores the reverse of the
    // string S
    string P = S;

    // Reverse the string P
    reverse(P.begin(), P.end());

    // If S is equal to P
    if (S == P)
    {
        // Return "Yes"
        return 1;
    }
    // Otherwise
    else
    {
        // return "No"
        return 0;
    }
}
ll fnc(ll x, ll y, ll d)
{
    ll count = (y - x) / d;
    if ((y - x) % d == 0)
    {
        count--;
    }
    return count + 1;
}
string revs(string s)
{
    string ss;
    for (ll i = 0; i < s.size(); i++)
    {
        ss.push_back(s[s.size() - 1 - i]);
    }
    return ss;
}
ll orr(ll n, ll m)
{
    ll rr = 1 << (m - 1);
    return rr | n;
}

// Code for problem goes here.................................................................................
ll mod = 998244353;
void solve()
{
    string s;
    cin>>s;
    ll n=s.length();
    string form1="",form2="";
    for(ll i=0;i<n/2;i++)
    {
        form1+=s[i];
        form2="";
        for(ll j=i+1;j<n;j++)
        {
            if(form2.length()==0 && s[j]=='0')
            break;
            form2+=s[j];
        }
        if(form2.length()==0)
        continue;
        ll use1=stoi(form1);
        ll use2=stoi(form2);
        if(use2>use1)
        {
            cout<<use1<<" "<<use2<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)

    solve();

    return 0;
}


Comments

Submit
0 Comments
More Questions

1302. Deepest Leaves Sum
1209. Remove All Adjacent Duplicates in String II
994. Rotting Oranges
983. Minimum Cost For Tickets
973. K Closest Points to Origin
969. Pancake Sorting
967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST