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

×

How to resolve time limit exceed error from my program

http://www.codechef.com/problems/TSORT/

include <iostream>
#include <algorithm>
using namespace std;

int main()
{
int n;
cin>>n;
int s[n];
for(int k=0;k<n;k++)
cin>>s[k];
sort(s,s+n);
for(int m=0;m<n;m++
cout<<s[m]<<endl;
return 0;
}

I can't understand why it is giving time limit exceed and which sorting algorithm does sort(s,s+n) uses and what's is complexity ?? plz also suggest me some other algo to reduce complexity of my program!!

asked 06 Dec '14, 10:01

chaman_amit's gravatar image

1★chaman_amit
871413
accept rate: 0%

edited 06 Dec '14, 14:37

betlista's gravatar image

3★betlista ♦♦
16.9k49115225

Post a link to your code instead of pasting the entire code here.

(06 Dec '14, 11:26) gautam943★

Okk dude!!

(06 Dec '14, 13:08) chaman_amit1★

It's getting TLE due to slower I/O. Using scanf and printf this solution will get AC. Accepted code
This problem can also be solved using counting sort in O(n) time. C++ implementation

scanf printf faster than cin cout
STL Sort algorithm

link

answered 06 Dec '14, 11:25

gautam94's gravatar image

3★gautam94
474142646
accept rate: 11%

edited 06 Dec '14, 11:29

Thanks finally get my code accepted!!

(06 Dec '14, 13:13) chaman_amit1★

Why i getting code accepted in this case http://www.codechef.com/viewsolution/5503082 and not in that case due to time limit exceeded although these are same

http://www.codechef.com/viewsolution/5503067 Plz help me!!

(06 Dec '14, 13:49) chaman_amit1★
2

@chaman_amit If you got the answer for your question,then you should mark it as the correct answer,so that it won't appear in unanswered questions. :)

(06 Dec '14, 14:03) ansh1star0333★

I won't find any option to mark as correct answer , plz tell me so i ll do that!!

(06 Dec '14, 15:44) chaman_amit1★

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

Can anyone please explain me why it is giving TIME LIMIT EXCEEDED ?

link

answered 18 Feb '18, 21:58

samlmxh21's gravatar image

3★samlmxh21
1
accept rate: 0%

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:

×204
×40
×38

question asked: 06 Dec '14, 10:01

question was seen: 11,244 times

last updated: 18 Feb '18, 21:58