Codeforces Round #799 (Div. 4) 1692F - 3SUM Solution


 

Problem Link: https://codeforces.com/problemset/problem/1692/F

Solve 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;
int main()
{
    int t,i,j,k,n,a,x,y,z,s,f,b;
    cin>>t;
    while(t--)
    {
        cin>>n;
        map<int,int>mp;
        f=0;
        for(i=0; i<n; i++)
        {
            cin>>a;
            b=a%10;
            mp[b]++;
        }
        for(i=0; i<=9; i++)
        {
            for(j=0; j<=9; j++)
            {
                for(k=0; k<=9; k++)
                {
                    x=y=z=0;
                    if(mp[i]!=0)
                    {
                        x=1,mp[i]--;
                    }
                    if(mp[j]!=0)
                    {
                        y=1,mp[j]--;
                    }
                    if(mp[k]!=0)
                    {
                        z=1,mp[k]--;
                    }
                    if(x==1&&y==1&&z==1)
                    {
                        s=i+j+k;
                        if(s%10==3)
                        {
                            f=1;
                            break;
                        }
                    }
                    if(x==1)mp[i]++;
                    if(y==1)mp[j]++;
                    if(z==1)mp[k]++;
                }
            }
        }
        if(f==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<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 &g...

Powered by Blogger.