Submission #884589

# Submission time Handle Problem Language Result Execution time Memory
884589 2023-12-07T17:46:34 Z kokoue Odd-even (IZhO11_oddeven) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
string n;
string cnt2="0";
string sum="1";
void clean(string &s)
{
    int sz=s.size();
    int i=0;
    while(i<sz&&s[i]=='0')i++;
    if(i==sz) s="0";
    else
    {
        s=s.substr(i,sz-i);
    }
}
int equalSize(string &s1,string &s2)
{
    int sz1=s1.size(),sz2=s2.size();
    int max_sz=sz1;
    if(sz1<sz2)
    {
        int diff=sz2-sz1;
        max_sz=sz2;
        for(int i=0;i<diff;i++)
        {
            s1='0'+s1;
        }
    }
    if(sz2<sz1)
    {
        int diff=sz1-sz2;
        max_sz=sz1;
        for(int i=0;i<diff;i++)
        {
            s2='0'+s2;
        }
    }
    return max_sz;
}
string sumbig(string s1,string s2)
{

    int summ,rem=0;
    char c;
    string result="";
    int max_sz=equalSize(s1,s2);
    for(int i=max_sz-1;i>=0;i--)
    {
        summ=(s1[i]-'0')+(s2[i]-'0')+rem;
        rem=summ/10;
        c=summ%10+'0';
        result=c+result;
    }
    if(rem) result='1'+result;
    return result;
}
string diff(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size(),lamp,rem=0,diff;
    string result;
    char c;
    if((sz2>sz1) || (sz1==sz2 && s1<s2))
    {
        swap(s1,s2);
        lamp=1;
    }
    int max_sz=equalSize(s1,s2);
    for(int i=max_sz-1;i>=0;i--)
    {
        diff=(s1[i]-'0'-rem)-(s2[i]-'0');
        rem=0;
        if(diff<0){diff+=10;rem=1;}
        c=diff+'0';
        result=c+result;
    }
    clean(result);
    return result;
}
string multy(string s,int dig)
{
    int sz,max_sz,mult,rem=0;
    sz=s.size();
    string result;
    string c;
    if(dig)
    {
        for(int i=sz-1;i>=0;i--)
        {
            mult=(s[i]-'0')*dig+rem;
            rem=mult/10;
            c=mult%10+'0';
            result=c+result;
        }
        if(rem>0){c=rem+'0';result=c+result;}
    }
    else result="0";
    return result;
}
bool cmpBig(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size();
    if(sz1>sz2) return true;
    if(sz1==sz2)
    {
        if(s1>s2) return true;
    }
    return false;
}
bool cmpBig2(string s1,string s2)
{
    int sz1=s1.size(),sz2=s2.size();
    if(sz1>sz2) return true;
    if(sz1==sz2)
    {
        if(s1>s2) return true;
        if(s1==s2) return true;
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    string cnt2="0";
    string sum="1";
    int br=0;
    while(cmpBig(n,"1") && br<100)
    {
    //    cout<<"n="<<n<<", sum="<<sum<<", cnt2="<<cnt2<<"\n";
        if(cmpBig(n,sumbig(cnt2,"1"))) sum=sumbig(sum,sumbig("1",multy(cnt2,2)));
        else {sum=sumbig(sum,multy(diff(n,"1"),2));}
    //    cout<<"n="<<n<<", sum="<<sum<<", cnt2="<<cnt2<<"\n";
        cnt2=sumbig(cnt2,"1");
        if(cmpBig2(cnt2,n)) break;
        n=diff(n,cnt2);
       // cout<<"n="<<n<<", sum="<<sum<<", cnt2="<<cnt2<<"\n";
        br++;
    }
    cout<<sum<<"\n";
    return 0;
}

Compilation message

oddeven.cpp: In function 'std::string diff(std::string, std::string)':
oddeven.cpp:60:37: warning: variable 'lamp' set but not used [-Wunused-but-set-variable]
   60 |     int sz1=s1.size(),sz2=s2.size(),lamp,rem=0,diff;
      |                                     ^~~~
oddeven.cpp: In function 'std::string multy(std::string, int)':
oddeven.cpp:82:12: warning: unused variable 'max_sz' [-Wunused-variable]
   82 |     int sz,max_sz,mult,rem=0;
      |            ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -