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 1100. Final Standings

Is it possible to use radix sort?
Posted by Evil Cheater 28 Apr 2004 08:16
I was trying to use radix sort but I got MLE (2 array [1..150000] and  one [0..100], all of longint).
I not very familiar with radix sort and I was wondering if there's a way to sort the data in the same array I'm storing them.

   Thanks!
Just counting sort :) (-)
Posted by Dmitry 'Diman_YES' Kovalioff 28 Apr 2004 10:15
Re: Just counting sort :) (-)
Posted by Evil Cheater 30 Apr 2004 00:16
I'm still having troubles. My program can sort all the data by m, but for equal m the output doesn't necesarly goes in the same order as in the input. E.g., for the sample input I get this (lines 2 and 3 are swapped):
3 5
22 4
26 4
16 3
20 3
1 2
11 2
7 1

I could have them order correctly if I could use one extra array but I can not find the way to do it in the same array. Is there a way to do that, or do I have to go through the array of data 101 times? Here's my code:

Var
   i,m,n,t: Longint;
   s: array [0..100] of longint;
   d: array [1..150000] of longint;

Begin
     readln(input,n);
     for i:= 1 to n do
         begin
         readln(input,t,m);
         Inc(s[m]);
         d[i]:= -(1000*t+m);
         end;
     for i:= 1 to 100 do
         Inc(s[i],s[i-1]);
     for i:= 1 to n do
         begin
         while (d[i]<0) do
               begin
               d[i]:= -d[i];
               m:=  d[i] mod 1000;
               t:= d[s[m]]; d[s[m]]:= d[i]; d[i]:= t;
               Dec(s[m]);
               end;
         end;
     for i:= n downto 1 do
         writeln(output,d[i] div  1000,' ', d[i] mod  1000);
End.
Re: Just counting sort :) (-)
Posted by mkd 30 Apr 2004 02:49
You don't have to sort anything. Just read input and write output :P
code like:

read teams
for i=100 to 0 do
  write teams where score==i

;P

mkd
Re: Just counting sort :) (-)
Posted by Evil Cheater 30 Apr 2004 04:11
Thanks, I got AC using that. But I still think there must be a better way...
another solution
Posted by mkd 30 Apr 2004 05:08
Well, it wouldn't work if score could be in range 0..500 or greater. But you are right - there is a way to solve it even with such ranges.
You'd just have to store team's IDs with the same score in some linked list. In order to avoid MLE a list element should have around 500 team IDs. Then you just print these lists for each score.
It works (I tried it) but it's not much faster for the 1100 test data (0.3 sec, while the previous solution 0.35 sec).

mkd