×

# INTEST : Time Limit Exceeded in C++

 1 I am trying to test my I/O methods via problem: INTEST http://www.codechef.com/problems/INTEST. On submitting it says time-limit exceeded. I previously submitted the similar problem in C, which gets accepted and takes 1.3 sec but for C++, its going beyond 8 sec. Is there any serious bug in my code or my I/O method is really so bad. Please help guys. As I am trying to switch from C to C++, its really demoralizing. Here is my source code: #include using namespace std; int main(){ int test, div; cin >> test >> div; int count = 0; int num; while(test--){ cin >> num; count += (num%div ? 0 : 1); } cout << count << endl; return 0; }  asked 19 Dec '13, 21:46 85●4●8●14 accept rate: 22%

 1 http://discuss.codechef.com/questions/32104/intest-time-limit-exceeded-how-to-shorten-time-duration-taken-to-run-this-program?page=1#32122 cout/cin simply is too slow, check the above link. You can either use scanf/printf for much faster I/O or as @kuruma explains - turn off auto sync with stdio and then using cout/cin will give you the time advantage. Cheers answered 19 Dec '13, 21:58 826●6●12●24 accept rate: 18%
 1 hey i think as cin is tied with cout it will be slow you can view my accepted code here is link for more help http://codeforces.com/blog/entry/5217 answered 19 Dec '13, 22:16 31●1●1●5 accept rate: 0%
 0 thanx guys..:D answered 20 Dec '13, 21:36 85●4●8●14 accept rate: 22%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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,917
×266
×75
×49
×49
×38

question asked: 19 Dec '13, 21:46

question was seen: 4,332 times

last updated: 20 Dec '13, 21:36