ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1684. Jack's Last Word

For everyone who thinks that his solution( C++ ) is correct, but has TLE..
Posted by PersonalJesus 8 Sep 2009 23:01
Do NOT use STL's strings, use standart C char arrays instead. That makes a HUGE difference in the time and memory complexity. I hope that this will be helpful to somebody:)
Re: For everyone who thinks that his solution( C++ ) is correct, but has TLE..
Posted by fmm 20 Jun 2010 05:32
i disagree, my solution takes 0.046 seconds...
and i use string, vector
Re: For everyone who thinks that his solution( C++ ) is correct, but has TLE..
Posted by 2rf [Perm School #9] 25 Jul 2010 21:32
PersonalJesus wrote 8 September 2009 23:01
Do NOT use STL's strings, use standart C char arrays instead. That makes a HUGE difference in the time and memory complexity. I hope that this will be helpful to somebody:)

STL string - TL 12, 10 MB used.
Char arrays - AC 0.031, 1.24 MB used...
Re: For everyone who thinks that his solution( C++ ) is correct, but has TLE..
Posted by IgorKoval(from Pskov) 14 Dec 2011 16:09
I got TLE. But after changing "s1.size()" on "long ns1 = s1.size()" and "s2.size()" on "long ns2" got AC. =)
And I  changed "vector" on "deque"( for deleting elements from begining ).

Edited by author 14.12.2011 16:27

Edited by author 14.12.2011 16:30
Re: For everyone who thinks that his solution( C++ ) is correct, but has TLE..
Posted by ASK 30 Jan 2014 23:22
Got 0.062 and 1485 KB with pure STL and strings: just start your program with

 cin.sync_with_stdio(false);

Btw, to get a O(n) solution consider that if a suffix of the last word is a prefix of the first word (check thru hash), then it is safe to assume that this suffix is in the answer.