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
Post a Comment