CNDYGAME - Editorial

oo yes I got it
Subtask 2 test cases were weak

What is ig?

Can anyone tell where i am wrong.
https://www.codechef.com/viewsolution/39448736

can’t agree more :joy:

Can anyone tell where I am wrong? Or give some tcs. It passes 1 tcs from Subtask 2
https://www.codechef.com/viewsolution/39658436

Can anyone provide a test case for subtask 1 (15 pts) .Thanks in advance.
https://www.codechef.com/viewsolution/39520691
It got accepted for 85 pts but WA for 15 pts. Please, someone, provide a test case.

You forgot taking mod while printing the answer at line 96

yeah , in start i was solving it like that , and realized that it is very hard. but then saw that numbers are distinct.

There were some edge cases but you have 10 days to solve. I think its okay to have an ugly problem in a 10-day long contest(not only implementation wise).

There was nothing to learn

This was intended to be the first problem of div 1. We can’t put something beginners don’t even know of. Also these kind of ugly problems can be attempted by both beginners as well as experienced ones without any knowledge of fancy DS.

I have seen some uglier problems in past that might frustrate people for a long time but that teaches you to write neat codes for debugging later(rather than just making your code ugly too by handling tens of cases separately and praying your submission somehow passes) and improves observation skill as well.

I’ll not put this problem in a short contest but it can arguably fit in a long contest.

10 Likes

Thank you!!!

1 Like

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
#define po pop_back
#define f(i,n) for(ll i = 0; i < n; i++)

ll mod = 1e9+7;

int main()
{

 #ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 #endif
 int t; cin>>t;
 while(t--)
 {
      ll n; cin>>n;
      ll a[n];

      f(i,n) cin>>a[i];
       
      ll q; 
      cin>>q;
      while(q--)
      {
        ll r;
        cin>>r;
        ll sum = 0;

        if(a[0] == 1)
        {
          if((r+n-1)/n != 1 && r%n == 1)
          {
            cout<<((r+n-1)/n -1)<<endl;
          }
          
          else
          cout<<(r+n-1)/n<<endl;
          continue;
        }

        if(a[n-1] == 1)
        {
          f(i,r)
          {
            
            sum += a[i%n];

            if(i != r-1 && (a[i%n]%2 == 1) && (i%n != n-1))
              sum--;
          }
          cout<<sum%mod<<endl;
          continue;
        }

         

         
          f(i,r)
            {
              if(a[(i+1)%n] == 1)
              {
                if(i == r-2)
                  {
                    if(a[i%n]%2)
                    sum += a[i%n];
                    
                    else
                    sum += (a[i%n]+1);
                  }

                else
                { 
                if(a[i%n]%2)
                    sum += a[i%n];
                    
                else
                    sum += (a[i%n]-1);}

                i++;
                continue;
                
              }
              
              sum += a[i%n];

              if(i != r-1 && a[i%n]%2 == 1 && i%n < n-1)
                sum--;

              if(i != r-1 && i%n == n-1 && a[i%n]%2 == 0)
                sum--;
               
               
            }

        cout<<sum%mod<<endl;

        
      }  
      

      
 
 }
 


 return 0;

}

What is wrong with my code . This code is of only 15 points , I am seriously frustrated with this question.

Your code was too fast to solve the subtask!.
:slightly_smiling_face:

1 Like

Thanks :innocent: :innocent: :innocent: :innocent: :innocent:

@utkarsh911 Please look at this to help me. I do not want to waste my hard work to solve this problem.

There are multiple missing cases in your code, even the ones mentioned in the editorial. I’ll suggest you to read the editorial once and figure it out yourself

just annoying , only increased my wrong submissions !

Please Help me with TLE, I don’t know why I am getting TLE my time complexity is O(N+Q)
https://www.codechef.com/viewsolution/39666189

Use fast IO and declare long long mod as const long long mod.

2 Likes

will that make a significant change ?
what is fast IO

4 5 1 7 3
for r = 3 ,
ans = 4 + 5 = 9
Your o/p = 10

1 Like