Skip to main content

Codeforces round 1030(C. Vasya and Golden Ticket)


 first sum the string then divide it & check

   Example:530178 sum=24
   so it can divided into 2,3,4,6,8,12(these can be substring sum)
   if we get any of these then it will be YES
   5 3 0 =8
   1 7    =8
   8      =8
Some thinkable cases:0 0 0 
                     1 1 1 1 1
                     2 2 
Otherwise NO

///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
  angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;

int main()
{
    ll n,sum=0,flag=0;
    string str;
    set<ll>st;
    set<ll>::iterator it;
    map<ll,ll>mp;
    cin>>n>>str;
    for(ll i=0;i<str.size();i++)
    {
        if(mp.find(str[i]-48)==mp.end()) mp[str[i]-48]=1;
        else mp[str[i]-48]++;
    }
    for(ll i=0; i<str.size(); i++)
        sum+=(str[i]-48);
    for(ll i=1; i<=sqrt(sum); i++)
        if(sum%i==0)
            st.insert(i),st.insert(sum/i);
    for(it=st.begin(); it!=st.end() && flag==0; it++)
    {
        ll num=*it,ofsec=0,cnt=0;
        for(ll i=0; i<str.size(); i++)
        {
            ofsec+=(str[i]-48);
            if(ofsec==num)
                cnt++,ofsec=0;
            if(ofsec>num)
                break;
            if(i==(str.size()-1) && (sum/num)==cnt && cnt!=1)
            {
                flag=1;
                break;
            }
        }
    }
    if(flag || mp.size()==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}
///Alhamdulillah

Problem link:https://codeforces.com/contest/1030/problem/C

Comments

Popular posts from this blog

Codeforces Beta Round #53 (A. Square Earth?)

Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is represented in base b using   namespace  std; typedef   long   long ...

Codeforces round 1676(A. Lucky?)

Just count the  first three  &  last three  number ///Bismillahir Rahmanir Rahim ///Author: Tanvir Ahmmad ///CSE,Islamic University,Bangladesh #include< iostream > #include< cstdio > #include< algorithm > #include< string > #include< cstring > #include< sstream > #include< cmath > #include< cstring > #include< vector > #include< queue > #include< map > #include< set > #include< stack > #include< vector > #include< iterator > #include   < functional >   ///sort(arr,arr+n,greater<int>()) for decrement of array /*every external angle sum=360 degree   angle find using polygon hand(n) ((n-2)*180)/n*/ ///Floor[Log(b)  N] + 1 = the number of digits when any number is repres...

AtCoder Beginner Contest 237(D - LR insertion)

Problem solving criteria:stack (https://www.cplusplus.com/reference/stack/stack/) Think about the first input: LRRLR That means  0 ->(L)-> 1 ->(R)-> 2 ->(R)-> 3 ->(L)-> 4 ->(R)-> 5 so we just need to save first R right number  in  an  array (vector) & other number saves  in  a stack. 0 ->(L)-> 1   general  array (vector)       stack( 0 )   top of stack= 0 1 ->(R)-> 2   general  array (vector)= 1      stack( 0 )   top of stack= 0 2 ->(R)-> 3   general  array (vector)= 1 , 2    stack( 0 )   top of stack= 0 3 ->(L)-> 4   general  array (vector)= 1 , 2    stack( 0 , 4 )...