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 1218. Episode N-th: The Jedi Tournament

Why WA?
Posted by Dmitry 'Diman_YES' Kovalioff 27 Oct 2002 16:36
It seems to me it is simple. Every count from 1 to 3000 is a sequence
3*3*3*...*2 or 3*3*3*...*3 or 3*3*3*...*4. Just long number
ariphmetics.
But Wrong Answer! Maybe my output is incorrect? Help me! Here is the
text of my program:

program DY_1222;
const
   ML=1000;
type
   TArray = array [1..ML] of integer;
var
   n,i1: longint;
   r: TArray;

{returns number of first non-zero position}
function GetStart(op: TArray): longint;
var
   prm: longint;
begin
   prm:=1;
   while op[prm]=0 do inc(prm);
   GetStart:=prm;
end;

{multiplies current array on 3}
procedure P(var op: TArray);
var
   prm: longint;
   mem: integer;
   buf: TArray;
begin
   mem:=0;
   FillChar(buf,SizeOf(buf),0);
   for prm:=ML downto GetStart(op) do
      begin
         buf[prm]:=(op[prm]*3+mem) mod 10;
         mem:=(op[prm]*3+mem) div 10;
      end;
   buf[prm-1]:=mem;
   op:=buf;
end;

begin
   Readln(n);
   if n>4 then
      begin
         r[ML]:=n-((n-2) div 3)*3;
         if r[ML]=0 then r[ML]:=1;
         for i1:=1 to (n-2) div 3 do P(r);
         for i1:=GetStart(r) to ML do Write(r[i1]);
      end
         else Write(n);
end.
Sorry :) It is to 1222 problem
Posted by Dmitry 'Diman_YES' Kovalioff 27 Oct 2002 16:38
Sorry :) It is to 1222 problem