I think that many internal computations with shorts are actually computed in 32-bit ints (as the judge's platform is 32-bit), this makes computation in ints a bit faster -- you don't have to convert from shorts to ints and back.
I made a test on my machine (x86, linux, gcc 3.3.5) with the following two programs:
#include <cstdio>
int main(){
#ifdef INT
int a, b, c, acc = 0;
#else
short a, b, c, acc = 0;
#endif
a = 81, b = 83, c = 7821;
for(int i = 0; i < 100000000; ++i){
acc = (acc + a * b) % c;
}
#ifdef INT
printf("%d\n", acc);
#else
printf("%hd\n", acc);
#endif
}
var boxes : array [1..30] of array [1..10] of integer;
graph : array [1..30] of array [1..30] of integer;
max_chain : array [1..30] of integer;
current_chain: array [1..30] of integer;
box_count,dimension,code,max_chain_length,current_chain_length : integer;
i,j,k : integer;
str,tmp : string;
procedure dimension_bublesort(box : integer);
var i, j , tmp : integer;
begin
for i := 1 to dimension-1 do begin
for j := dimension downto i+1 do
if(boxes[box,j] < boxes[box,j-1])then begin
tmp := boxes[box,j];
boxes[box,j] := boxes[box,j-1];
boxes[box,j-1] := tmp;
end;
end;
end;
function nest_box(a, b : integer):boolean;
var i : integer;
begin
for i := 1 to dimension do
if(boxes[a,i] >= boxes[b,i])then begin
nest_box := false;
Exit;
end;
nest_box := true;
end;
procedure compare_length;
var i:integer;
begin
if(max_chain_length < current_chain_length) then begin
max_chain_length:=current_chain_length;
for i:=1 to current_chain_length do max_chain:=current_chain;
end;
end;
procedure find_chain(box:integer);
var i:integer;
begin
current_chain_length:=current_chain_length+1;
current_chain[current_chain_length]:=box;
for i:=1 to box_count do begin
if(graph[box,i] = 1) then begin
find_chain(i);
compare_length;
current_chain_length:=current_chain_length-1;
end;
end;
end;
begin
while not EoF(input) do begin
ReadLn(box_count,dimension);
for i:=1 to box_count do begin
ReadLn(str);
for j:=1 to dimension-1 do begin
k:=1; tmp:='';
while(str[k] <> ' ') do begin
tmp:=tmp + str[k];
k:=k + 1;
end;
Val(tmp,boxes[i,j],code);
Delete(str,1,k);
end;
Val(str,boxes[i,dimension],code);
end;
for i:=1 to box_count do dimension_bublesort(i);
for i:=1 to box_count do
for j:=1 to box_count do graph[i,j]:=0;
for i:=1 to box_count do
for j:=1 to box_count do
if(nest_box(i,j) = true) then graph[i,j]:=1
else graph[i,j]:=0;
max_chain_length:=0;
for i:=1 to box_count do begin
max_chain:=0;
current_chain:=0;
end;
for i:=1 to box_count do begin
current_chain_length:=0;
find_chain(i);
end;
WriteLn(max_chain_length);
for i:=1 to max_chain_length do begin
if(i <> max_chain_length) then Write(max_chain,' ')
else WriteLn(max_chain);
end;
this is a huge code .
it is better to post your procedure than code for better undestanding
for the reader.
and you also may get the reply from all the programmers of different
languages .
Have you tried to compile it at all with gcc? This code just can't work - i is undeclared in line 79th.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...
I use "VC++.net" as development environment .
Using this compiler, that code doesn't suggest "CompileError".
Has it been optimized underground?
I have no idea...
////////////////////////////////////////////////////////////////////////////////
I'm Japanese, and I started studying "C++" a week ago.
So, it is hard for me to read and to solve problems.
Thank you, nice programer Krzysztof Duleba!
Last edited by jan-jun-john on Thu Feb 09, 2006 4:55 pm, edited 1 time in total.
VC++ .NET is a pretty good compiler, but as you say, during optimization phase strange things do happen. You can try setting all the warnings on and using Debug instead of Release, but I don't know if it will change a thing.
Since you have AC now, please remove your code from the board.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...