You are not logged in. Please login at www.codechef.com to post your questions!

×

"I want to ask a question" - Ask them all here!

Hello guys,

As you all are aware, many times there are genuine users who wish to ask a question, but dont have karma for it. They then, have to resort to means of either asking their question in other threads, or request someone to upvote them so they can ask a question.

As we have seen last month, some fake accounts were used in malpractices in discuss, and they also gained karma by "I want to ask a question" thing. Hence, now it is becoming increasingly difficult to differentiate between genuine users, and fake users.

This thread is my solution for it. Any user, with less than 3 karma who wants to ask a question is requested to ask it here, and if the question is upto standards (meaning it needs more than those "one line answers") then we (at least I ) will convert your "answer" here into a question.

In short, post your question here, and if its a good genuine question, it will get posted as a separate question by using "Convert to question" feature.

In case your question required only 1 line answers or such, we would comment it on your question.

You guys are requested to direct any such guy (who wants to ask a question) here and not "free-upvote" them, so that we can avoid any duplicate/irrelevant questions (as questions posted here would be verified first, before converting to question).

Note to @admin - We will require your active participation and help in events related to deletion of any spam content here. Also, since only admins are ones who could delete answers, it is requested that you keep an eye out on this thread.

With Regards

Vijju123

This question is marked "community wiki".

asked 09 May, 10:26

vijju123's gravatar image

3★vijju123
3.8k110
accept rate: 14%

wikified 09 May, 14:22

mathecodician's gravatar image

5★mathecodician
2.2k215

Users are requested to give their views as COMMENTS to this question.

Only questions should be posted in this thread (to keep it clean)

(09 May, 10:29) vijju1233★
1

Pretty cool idea

(09 May, 11:41) neilit19923★
2

I think it will be better as a community wiki.

(09 May, 14:22) mathecodician5★

If you feel so. :) . BTW, now i can also see the revision history :p

(09 May, 14:47) vijju1233★
1

Great initiative @vijju123 !

(19 May, 22:15) akashbhalotia2★

PLEASE NOTE-

ANY QUESTION RELATED TO ON-GOING CONTEST WILL BE STRICTLY DELETED.

(21 May, 22:43) vijju1233★

Please note- Inactive questions etc. will be removed after 24 hours of inactivity. Users are requested to tell if their query is answered or if there is still need to convert comment to Q .It will help us in managing this thread.

(22 May, 20:29) vijju1233★
showing 5 of 7 show all

12next »

include<iostream>

using namespace std; //Pre And Post Increment Behaivour int main(){ int a=2,b; b=a++ + a++; cout<<"The value is "<<b<<endl; //Output=5

a=2;
b=a++ + ++a;
cout<<"The value is "<<b<<endl;
//Output=6

a=2; 
b=++a + a++;
cout<<"The value is "<<b<<endl;
//Output=7 HOW? 
a=2; 
b=++a + ++a;
cout<<"The value is "<<b<<endl;
//Output=8 HOW??


return 0;
}

I couldn't understand the last Two outputs.. Can anyone help?

link
This answer is marked "community wiki".

answered 21 May, 13:57

xtraterestrial's gravatar image

0★xtraterestrial
1
accept rate: 0%

1

If you change the value of a variable more than once in c, like (++a + a++ + --a etc.) then its undefined behaviour. Its all on luck what gets printed. You got an output of 6, which is a nice co-incidence.

In short, unlike java, these operations lead to undefined behaviour in C (and perhaps c++?)

Comment if it answers your question.

(21 May, 14:04) vijju1233★

I am a learner in programming .Where can I search for algorithm .I mean ,tell me a good source website to learn algorithms.

link

answered 21 May, 19:26

ram_mahidhar's gravatar image

3★ram_mahidhar
111
accept rate: 0%

geeksforgeeks.org is best website for this. Also, there are tutorials on codechef, and many answers which deal with how to start coding/learn algorithms. Give forum a search (cant provide link atm, any other user who can is requested to provide link)

(21 May, 20:17) vijju1233★

I can't reply to ram_mahidhar directly, but here's a good book for beginners:

https://cses.fi/book.html

(21 May, 21:47) vasja5★
(2 days ago) gary_5710★

What is the best way to check my code execution time?

link

answered 22 May, 23:42

irikeish's gravatar image

2★irikeish
1
accept rate: 0%

@irikeish

Run it on "Code, Compile and Run" and it will show you the exact time.

If you mean execution time for larger test cases, meaning "if this algo will pass or not", just remember that online judge performs 10^8-10^9 instructions per second. So if your program is like-

for(i=0;i< n;i++) { for(j=0;j< n;j++) { .... } }

Then for every i, second loop repeats N times. Overall, things are performed N+N+N...(upto N times) = N x N = N^2 times

So if N is around 10^5, it requires 10^10 instructions which exceeds time limit.

You will get a fair idea like this and when you practice and look for new algos.

Do indicate via comment (on your answer)if this resolves your query or not. (Couldnt post as comment as it exceeded limit :/ )

(23 May, 00:00) vijju1233★

@irikeish you can use the clock() function defined in the time.h header file. your code could be like this.

#include <bits/stdc++.h>
using namespace std;
int main()
{
    clock_t start = clock();
    //your code part of which you want to check the execution time for.
    clock_t end = clock();
    double t=(double)(end-start)/CLOCKS_PER_SEC;
    //now the varialbe t contains the execution time in secs. Just print it to check the time.
    printf("%lf\n",t);
    return 0;
}
(23 May, 00:16) floating_point3★

can anyone tell me why im getting TLE in SNAKEEAT problem in snackdown_17 qualifier ! here is the link to my code https://www.codechef.com/viewsolution/13663672 ...and also suggest d best approach !

link

answered 24 May, 18:07

msd_007's gravatar image

2★msd_007
1
accept rate: 0%

edited 24 May, 18:11

vijju123's gravatar image

3★vijju123
3.8k110

for(int y=m-1;y>=0;y--) { a[y]=a[y]+1; if(a[y]>=b[r]) { c++; a[y-1]=a[y-2]; a[y-2]=0; } }

This loop inside the query loop makes your complexity O(NQ) in worst case and it would require ~10 seconds to solve. Read the editorial first, if doubt still persists, comment here and i will convert it into a question.

(24 May, 18:13) vijju1233★

There is another thread asking the same question, keep an eye there too. The methods followed are basically same.

(24 May, 18:17) vijju1233★

Why can't I submit my code for May Long Challenge? Up-solving the problems that you were not able to solve in a contest is a must. But the submission link is removed. Also, I want to ask about the editorials of the long contests. The May Long questions are still not provided with editorials. The last one : Is there a way by which I can view the test cases after the contest ends?

link

answered 25 May, 18:42

rohitthapliyal's gravatar image

2★rohitthapliyal
1
accept rate: 0%

The problems are moved to practice section. To easily get to the practice version of problem-

1)Click on weblink 2)remove the part "/MAY17" 3) HIT enter.

Regarding editorials, forum users cannot comment anything. Try mailing codechef about it, or try to ask the question as doubt here, we will surely help!

No, there is no way of viewing the test cases.

(25 May, 18:52) vijju1233★

That helped. So, there won't be any editorials?

(25 May, 22:14) rohitthapliyal2★

Depends...only @admin can provide any information on it, and its advised to mail them for this. However, i case you need an editorial urgently, one of the discuss members would love to write one. Just ask once :)

(25 May, 22:29) vijju1233★

ok thanks.

(2 days ago) rohitthapliyal2★

Can anyone tell me why this code is not functioning properly?Can we accept and display a string like this?

    main()
  {
   string a;char ch;

   for(int i=0;i<5;i++)
{
     cin>>ch;
      a[i]=ch;
}

     cout<<a;
    }
link

answered 2 days ago

senacoder111's gravatar image

0★senacoder111
1
accept rate: 0%

edited 2 days ago

vijju123's gravatar image

3★vijju123
3.8k110

Please give the link to question also. I will then convert it to a question.

(2 days ago) vijju1233★

if a is a string, dont use a[i] = ch. Use a= a+ch; This will have the desired effect.

(2 days ago) vijju1233★

Sir,thank you for replying,but why should we not use it like that?

(2 days ago) senacoder1110★

Well. I feel it can cause run time error due to "out of index" thing. We used this method in C, but there C was an array of char (length pre defined).

Here, we dont know length if string but we are making changes at i th index. Remember that string also gives out of index error just like array (eg - if arr[n+5] gives runtime error, then so will s[n+5]. Faced these issues during contests.

Treating it similar to array, i think you will get an error. But s=s+ch is different. It says "whatever be s, add ch to its end" , so theres no scope of going out of index here.

(2 days ago) vijju1233★
1

thank you very much sir,i will change it.

(2 days ago) senacoder1110★

Is using insertion sort in SNAKEEAT problem causing TLE?

https://www.codechef.com/status/SNAKEEAT,amanawasthi96

link

answered 2 days ago

amanawasthi96's gravatar image

0★amanawasthi96
1
accept rate: 0%

Insertion sort is O(N^2) in worst case and can cause TLE depending on input.

(2 days ago) vijju1233★

Hi everyone, can anyone tell me why am I getting WA with this code the problem CHEFSQ ? I've tried different test cases and they all seem to give me the correct answer...

Thanks !

link

answered 2 days ago

sysm's gravatar image

0★sysm
111
accept rate: 0%

Answer to sysm: The sub sequence doesn't have to be continuous, but the order of elements should be maintained. Input

1
5
1 2 3 4 5
3
1 3 5

Your Output:

No

Correct Output:

Yes

my C code

(2 days ago) divyansh_gaba75★

Haaaaaa. Thanks for your answer !

(2 days ago) sysm0★

Sir,my code for permut2

https://www.codechef.com/problems/PERMUT2 is not working properly,I am unable to debug it and desired output is not coming for a few problems. PlEASE HELP

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

link

answered 2 days ago

senacoder111's gravatar image

0★senacoder111
1
accept rate: 0%

Your question has been shifted here-

https://discuss.codechef.com/questions/99127/kindly-help-me-for-spoj-ambiguous-permutation

It has been upgraded into an individual question. Make sure to keep an eye there to clarify your doubts!

(2 days ago) vijju1233★

Thank you sir.

(yesterday) senacoder1110★

I got wrong answer in the samesnak problem asked in snack down qualifiers. Can anyone please tell me what's wrong with the code. Here's the link: https://www.codechef.com/viewsolution/13762975

link

answered 2 days ago

avi0_8's gravatar image

0★avi0_8
1
accept rate: 0%

Can you please check once the test cases provided by fellow members to other people who got WA? Have a look at similar questions and the errors, and then comment here if help is still needed. I will then convert it to a question (This question is being repeatedly asked, hence my request to have a check :) )

(2 days ago) vijju1233★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Tags:

×133
×61

Asked: 09 May, 10:26

Seen: 1,852 times

Last updated: 7 hours ago