Codeforces will be possibly unavailable in the period between Sep. 19, 19:00 (UTC) and Sep. 19, 21:00 (UTC) because of maintenance. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
43333542 Contestant:
John_Cena
1058C - 56 GNU C++14 Wrong answer on test 17 30 ms 8 KB 2018-09-23 17:58:22 2018-09-23 19:39:20
 
 
→ Source
#include<bits/stdc++.h>
using namespace std;

bool help(int &chosen,int &sum,vector <int> &nums)
{
    if(sum>chosen)
        return false;
    if(nums.empty()&&chosen==sum)
        return true;
    if(nums.empty())
        return false;
    if(chosen==sum)
        sum=0;
    int x=nums[0];
    sum+=nums[0];
    nums.erase(nums.begin());
    if(help(chosen,sum,nums))
        return true;
    nums.insert(nums.begin(),x);
    return false;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,chosen,sum;
    cin>>n;
    vector <int> a;
    string s;
    cin>>s;
    int i=0,j=n-1;
    while(s[i]=='0')
    {
        i++;
    }
    while(s[j]=='0')
        j--;
    for(int k=i;k<=j;k++)
        a.push_back(s[k]-'0');
    n=a.size();
    if(n==1)
    {
        cout<<"NO";
        return 0;
    }
    if(n==0)
    {
        cout<<"YES";
        return 0;
    }
    vector <int> pre(n+1);
    for(int i=0;i<n;i++)
        a[i]=s[i]-'0';
    for(int i=0;i<n;i++)
    {
        pre[i+1]=pre[i]+a[i];
    }
    for(int cl=1;cl<n;cl++)
    {
        chosen=pre[cl];
        sum=0;
        vector <int> t(a.begin()+cl,a.end());
        if(help(chosen,sum,t))
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details