2003 Canadian Computing Competition, Stage 2

Day 2, Problem 2: Longest Substring

Within a sequence S of integers, find the longest contiguous subsequence that contains every integer at most once.
In other words, find the longest contiguous subsequence in which no integer is repeated. If there are several such subsequences, find the one that occurs first in S.

Input

The input will consist of the elements of S, one per line, in sequence, followed by 0.
Each element of S is a positive integer less than 65536. You should not assume anything about the length of S.

Output

The output should contain the correct subsequence of S, one element per line.

Sample Input

1
9
5
3
1
2
8
3
9
0

Sample Output

9
5
3
1
2
8

All Submissions
Best Solutions


Point Value: 20 (partial)
Time Limit: 2.00s
Memory Limit: 3M
Added: Dec 28, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

I am getting RE. I think it is for memory limit...
My code is taking 3.07M/3M.how can i reduce my memory ? . hint please :)


Try to avoid the linked lists please. They actually use more memory than simple arrays, and are slower also. They will not allow you to use more memory than you would otherwise be allowed.

All the AC solutions so far are in C++. C++ has a convenient function that allows you to "rewind" a file, that is, start reading from the beginning again. In Pascal on Linux the following should work:
 
assign(input,'/dev/stdin');
reset(input);

After these lines have been executed, it should be possible to read the input over again. I leave it to you to determine how to use this knowledge.
Unfortunately, Pascal does not allow you to seek to the beginning of text files such as input and output.

I've never had Invalid Return as a judge result before. What exactly does it mean?

Hmm.. ok. The detailed error should appear in your output now (the IR is basically a RE here)

why has the time limit on this problem been changed?

It hasn't, I've added a tricky test case.

To make it challenging, the memory limit is very strict.
The input is not guaranteed to fit in memory.