CHECHOC - Editorial

it is accepted but it is not the correct code
let see for

1
19 19 101 189

answer should be 34121 , however this code gives 36461

whats wrong in this please help
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
long long int n,i,j,m,x,y,p,count=0;
cin>>n>>m>>x>>y;
long long int a[n][m];
if(y>=x2)
{
count=x
n*m;
cout<<count<<endl;
}
else
{
if(x>y)
{
for(i=0;i<n;i++)
{
if(i%2==0)
{
for(j=0;j<m;j++)
{
if(j%2==0)
{
count=count+y;
}
else
{
count=count+0;
}
}}
else
{
for(j=0;j<m;j++)
{
if(j%2==0)
{
count=count+0;
}
else
{
count=count+y;
}

			}
		}
    }	
			}
		else
	{
	for(i=0;i<n;i++)
	{
		if(i%2==0)
		{
		for(j=0;j<m;j++)
		{
			if(j%2==0)
			{
				count=count+x;
			}
			else
			{
				count=count+y-x;
			}
		}}
		else
		{
        	for(j=0;j<m;j++)
			{
			if(j%2==0)
			{
				count=count+y-x;
			}
			else
			{
				count=count+x;
			}
				
			}
		}
    }}
	cout<<count<<endl;
    }
}

}

Fails on

1
7 3 8 2

Correct ans- 22. Your output- 28

: ( missed 100 pts for 1*1 testcase

for mn=1 and y<x why should we fill x in the cell as it is obvious from second proposition that sum is less than y so it is obvious that each element should be either less than y or equal to.
Filling x in 1
1 matrix (x>y) is really out of context.
That costed 100 points and wasted a lot of time too. Even if one is able to find out that corner case is m==1 and n==1,the logic which prob setter used indeed beyond interpretation

can someone please tell me why my code is giving WA.
https://www.codechef.com/viewsolution/36042692

@abiding_haze7
My code is giving ans as 2 only

Fails on
1
7 3 8 2
Correct ans-22

Can someone please tell me what is wrong in my code?
Getting WA.
https://www.codechef.com/viewsolution/35964790

thank you now i got it

@yash_chandnani , sir i tested your code on inputs 1 1 6 5 and your code gives answer 6 , which is impossible against the given statement that sum should not be greater than y. please clarify sir, or if someone else can !

if there’s only one cell there are no pairs of cells so the limit of y does not apply to anything

1 Like

Damn , missed only the base case

Please check my code, I don’t get where I did wrong solution

It is not clear whether your remarks is about my question(209) or not. If so, the test case given by you returns answer as 34121 and not 36461 as told by you. Please check again and if possible please tell me where I have done the mistake?

https://www.codechef.com/viewsolution/35987993

Please anyone help me.

Can anyone tell me what’s wrong with my solution?
https://www.codechef.com/viewsolution/36047769

Since you have written your code in py , I can’t help ( I know cpp only)
If you know cpp then use it
CHECHOC WA FINDER

It will gives you all posssible Test Cases where you failed.
Try Once, you will Love it!!

The beauty about this question was the base case (1x1) :slight_smile:

1 Like

i literally submitted this code 7 time got WA and time penalty for 70 mins

  void test_case(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int arr[n][m];
    lld sum=0;
    if(n<2){
        cout<<x<<endl;
        return;
    }
    x=min(x,y);
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            if((i+j)%2==0){
                sum+=x;
            }
            else{
                sum+=max(0,min(x,y-x));
            }
        }
    }
    cout<<sum<<endl;
}

ps did you figure out mistake in my code.

what was my mistake is only edge case condition didn’t satisfy.
Here is the correct code to it:

void test_case(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int arr[n][m];
    lld sum=0;
    if(n*m<2){
        cout<<x<<endl;
        return;
    }
    x=min(x,y);
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            if((i+j)%2==0){
                sum+=x;
            }
            else{
                sum+=max(0,min(x,y-x));
            }
        }
    }
    cout<<sum<<endl;
}

total wasted my rank should have been under 200-300 but ended up getting 2000+ xoxo.

Well, Thankyou for the reply. I corrected the base case but then also, it’s showing WA after submission!