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

×

For DISHOWN July14 same solution in C++ 4.3.2 got TLE & got AC in C

For the problem DISHOWN in JULY14 challenge I first tried in C++ 4.3.2 and got TLE then I uploaded the same code(of course changed cin & cout to scanf and printf) got AC in C.

Admin/Anyone please exlain the reasons for this:

C++ 4.3.2 Submission(TLE): http://www.codechef.com/viewsolution/4284093

C Submission(AC): http://www.codechef.com/viewsolution/4284183

Thank's in Advance.

asked 16 Jul '14, 13:35

codeman004's gravatar image

4★codeman004
7014
accept rate: 25%

edited 01 Aug '14, 14:20

admin's gravatar image

0★admin ♦♦
19.8k350498541


Yes 'cin' and 'cout' are slower than scanf() and printf().To make them faster you can use :

int main() {
     ios_base::sync_with_stdio(false); cin.tie(0);
    // rest of your code
    return 0;
}

Here are some of the links which may help you !
http://discuss.codechef.com/questions/23083/difference-caused-in-run-time-by-scanfprintf-when-used-in-place-of-coutcin
http://discuss.codechef.com/questions/2589/scanfprintf-vs-cincout

http://discuss.codechef.com/questions/37795/printf-and-scanf-for-pair#37805

link

answered 16 Jul '14, 13:45

achaitanyasai's gravatar image

5★achaitanyasai
2.2k61748
accept rate: 10%

@achaitanyasai Does that difference(cin & cout to printf & scanf) will cause this much effect I mean TLE to AC..??

(16 Jul '14, 13:48) codeman0044★

It depends, if the constraints are tight(large) then you may have chance to get TLE if you use cin/cout. But in most of the cases it doesn't matter.

(16 Jul '14, 13:50) achaitanyasai5★

@achaitanyasai Thanks.. :)

(16 Jul '14, 13:53) codeman0044★
toggle preview
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

Question tags:

×1,916
×1,490
×690
×20
×8

question asked: 16 Jul '14, 13:35

question was seen: 1,002 times

last updated: 01 Aug '14, 14:20