Which test case am i missing?

Which test case am i missing?



I was solving a question. But I am missing something. There's some test case for which my solution is wrong. I need to find that test case.
For the other subtask, it is saying that execution took too long.



Chef will have access to Discourse if his knowledge and power become exactly equal to N and M respectively. Initially, he has power
1 and knowledge 1.



Chef can perform actions of the following types to improve his skills:



Chef can only install ShareChat at most once. The remaining actions may be performed any number of times and the actions may be
performed in any order.



Help Chef find out whether it is possible to move from Discuss to Discourse.



Input



The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.



The first and only line of each test case contains four space-separated integers N, M, X and Y.



Output



For each test case, print a single line containing the string "Chefirnemo" if it is possible to reach the required knowledge and
power or "Pofik" if it is impossible



you can also visit this link to read the question
Link to question https://www.codechef.com/SEPT18B/problems/CHEFADV
My solution-


#include<stdio.h>
int main()

int t;
scanf("%d",&t);
while(t--)

long int n,m,x,y,power,know;
scanf("%ld%ld%ld%ld",&n,&m,&x,&y);
power=1;
know=1;
if(power+1==m && know+1==n)
printf("Chefirnemon");
else
while(power+y<m)
power=power+y;
if(power+y==m)
power=power+y;
while(know+x<n)
know=know+x;
if(know+x==n)
know=know+x;
if(power==m && know==n)
printf("Chefirnemon");
else if(power+1==m && know+1==n)
printf("Chefirnemon");
else
printf("Pofikn");


return 0;






Please give complete information of the required help in the question instead of sharing links. it will help people to help you.

– Zeeshan Adil
Sep 8 '18 at 15:25






TIME LIMIT EXCEEDED

– Slycoder
Sep 8 '18 at 15:45






read about the modulo operation (%) It should help with the TLE problem

– Walter
Sep 8 '18 at 15:46


%






You tagged this C++, but it looks like C to me. I don't see any C++ usage.

– abelenky
Sep 8 '18 at 15:49


C++


C






Wonder if problems from active contest are off-topic here?!

– CinCout
Sep 8 '18 at 16:19




3 Answers
3



Your code fails if either x==1 and (m-1)%y==1 or vice versa (i.e. y==1 and (n-1)%x==1). Then your iteration will increase power to n and know to m-1 when installing ShareChat cannot help. However, had you increased power only to n-1, installing ShareChat would have obtained a match.


x==1


(m-1)%y==1


y==1


(n-1)%x==1


power


n


know


m-1


power


n-1



A correct solution should treat the installation of ShareChat more careful. For example


bool chefirnemo(int n, int m, int x, int y)

// 0 check that input is okay
assert(1<=n && 1<=m && 1<=x && 1<=y);
// 1 change to the equivalent problem where power
// and knowledge are 0 initially
--n; --m;
// 2 try w/o installation of ShareChat:
if (n>=0 && (n%x)==0 && m>=0 && (m%y)==0)
return true;
// 3 install ShareChat
--n; --m;
// 4 try again
return (n>=0 && (n%x)==0 && m>=0 && (m%y)==0);






Yes, that's my bullet point #2.

– Ben Voigt
Sep 8 '18 at 16:18






Btw, this website lives from people being grateful, which is reflected by accepting an answer and/or up-voting an answer or a question.

– Walter
Sep 9 '18 at 12:33






Sorry, i'm new. Can you reply to my previous comment please?

– Slycoder
Sep 10 '18 at 4:08






Even your answer isn't correct my friend. I tried out with some test cases,it's not giving the desired answer. for eg- 2 2 1 2 it should be true. But your solution is giving it as false. And your loop becomes infinite in test cases like 5 2 3 0

– Slycoder
Sep 10 '18 at 15:42







I thought 1≤N,M,X,Y≤109, so 5,2,3,0 is not allowed. And I fixed the other issue (btw, my code has no loop, so it's not clear what you meant).

– Walter
Sep 13 '18 at 15:17




Your rules don't guarantee that the inputs are positive. If X or Y is zero, your loops never terminate. (Note, this is a problem with your paraphrase, the challenge rules do assure positive values)



Test case: 2 2 0 0



Test case: 2 4 0 2



Test case: 4 4 1 0



How many times you apply (+X,0) and (0,+Y) should depend on whether the (+1,+1) action is used... but you have already locked in your decision.



Test case: 5 6 1 2






The problem has following constraints: Constraints 1≤T≤1,000 1≤N,M,X,Y≤109

– Slycoder
Sep 8 '18 at 16:15







@Slycoder: The problem does. Your question doesn't.

– Ben Voigt
Sep 8 '18 at 16:17






Thanks! I find it difficult Identifying such test cases where my solution fails. Can you please tell me how it's done? how did you find out ?

– Slycoder
Sep 9 '18 at 7:32






And my code is very inefficient right?

– Slycoder
Sep 9 '18 at 7:41



although Walter does point out the possible hints.
the solution does not seem to be working.






Yes absolutely. His code couldn't't overcome the shortcomings my code had. It has the same problens

– Slycoder
Sep 11 '18 at 1:36






This should just be a comment

– dodococo
Sep 12 '18 at 13:37



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế