I couldn't see where is the problem in my program. I receive the message "Wrong Answer" but I think that it's OK...
Code: Select all
[pascal]
program p254(input,output);
const
zero:string[31]='0000000000000000000000000000000';
unu:string='0000000000000000000000000000001';
x:array[0..100] of string=
('0000000000000000000000000000000',
'0000000000000000000000000000001',
'0000000000000000000000000000003',
'0000000000000000000000000000007',
'0000000000000000000000000000015',
'0000000000000000000000000000031',
'0000000000000000000000000000063',
'0000000000000000000000000000127',
'0000000000000000000000000000255',
'0000000000000000000000000000511',
'0000000000000000000000000001023',
'0000000000000000000000000002047',
'0000000000000000000000000004095',
'0000000000000000000000000008191',
'0000000000000000000000000016383',
'0000000000000000000000000032767',
'0000000000000000000000000065535',
'0000000000000000000000000131071',
'0000000000000000000000000262143',
'0000000000000000000000000524287',
'0000000000000000000000001048575',
'0000000000000000000000002097151',
'0000000000000000000000004194303',
'0000000000000000000000008388607',
'0000000000000000000000016777215',
'0000000000000000000000033554431',
'0000000000000000000000067108863',
'0000000000000000000000134217727',
'0000000000000000000000268435455',
'0000000000000000000000536870911',
'0000000000000000000001073741823',
'0000000000000000000002147483647',
'0000000000000000000004294967295',
'0000000000000000000008589934591',
'0000000000000000000017179869183',
'0000000000000000000034359738367',
'0000000000000000000068719476735',
'0000000000000000000137438953471',
'0000000000000000000274877906943',
'0000000000000000000549755813887',
'0000000000000000001099511627775',
'0000000000000000002199023255551',
'0000000000000000004398046511103',
'0000000000000000008796093022207',
'0000000000000000017592186044415',
'0000000000000000035184372088831',
'0000000000000000070368744177663',
'0000000000000000140737488355327',
'0000000000000000281474976710655',
'0000000000000000562949953421311',
'0000000000000001125899906842623',
'0000000000000002251799813685247',
'0000000000000004503599627370495',
'0000000000000009007199254740991',
'0000000000000018014398509481983',
'0000000000000036028797018963967',
'0000000000000072057594037927935',
'0000000000000144115188075855871',
'0000000000000288230376151711743',
'0000000000000576460752303423487',
'0000000000001152921504606846975',
'0000000000002305843009213693951',
'0000000000004611686018427387903',
'0000000000009223372036854775807',
'0000000000018446744073709551615',
'0000000000036893488147419103231',
'0000000000073786976294838206463',
'0000000000147573952589676412927',
'0000000000295147905179352825855',
'0000000000590295810358705651711',
'0000000001180591620717411303423',
'0000000002361183241434822606847',
'0000000004722366482869645213695',
'0000000009444732965739290427391',
'0000000018889465931478580854783',
'0000000037778931862957161709567',
'0000000075557863725914323419135',
'0000000151115727451828646838271',
'0000000302231454903657293676543',
'0000000604462909807314587353087',
'0000001208925819614629174706175',
'0000002417851639229258349412351',
'0000004835703278458516698824703',
'0000009671406556917033397649407',
'0000019342813113834066795298815',
'0000038685626227668133590597631',
'0000077371252455336267181195263',
'0000154742504910672534362390527',
'0000309485009821345068724781055',
'0000618970019642690137449562111',
'0001237940039285380274899124223',
'0002475880078570760549798248447',
'0004951760157141521099596496895',
'0009903520314283042199192993791',
'0019807040628566084398385987583',
'0039614081257132168796771975167',
'0079228162514264337593543950335',
'0158456325028528675187087900671',
'0316912650057057350374175801343',
'0633825300114114700748351602687',
'1267650600228229401496703205375');
type rec=record n:integer;
s:string;
end;
var nrp,n,A,B,C:integer;
m:string;
aux,k:integer;
t:array[1..3] of integer;
function cifra(ch:char):integer;
var c:integer;
begin
c:=ord(ch)-ord('0');
cifra:=c;
end;
function caracterul(c:integer):char;
var ch:char;
begin
ch:=chr(c+ord('0'));
caracterul:=ch;
end;
function k_max(m:string):integer;
var k:integer;
begin
k:=1;
while x[k]<=m do
k:=k+1;
k_max:=k-1
end;
procedure citire(var n:integer;var m:string);
begin
readln(input,n,m);
delete(m,1,1);
while length(m)<31 do
insert('0',m,1);
end;
procedure scad(var s1:string;s2:string);
{ s1:=s1-s2 }
var t,c1,c2,c,j,t1:integer;
begin
t:=0;
for j:=31 downto 1 do
begin
c1:=cifra(s1[j]);
c2:=cifra(s2[j]);
if c1-t<c2 then
t1:=1
else
t1:=0;
c:=c1-t+t1*10-c2;
t:=t1;
s1[j]:=caracterul(c);
end;
end;
begin
citire(n,m);
nrp:=0;
while not ((n=0) and (m=zero)) do
begin
nrp:=nrp+1;
A:=1; B:=2; C:=3;
t[A]:=n; t[B]:=0; t[C]:=0;
repeat
k:=k_max(m);
{k discuri de pe A pe C sau
de pe A pe B}
t[A]:=t[A]-k;
if (n-k) mod 2=1 then
t[C]:=t[C]+k
else
t[B]:=t[B]+k;
scad(m,x[k]);
if m<>zero then
{1 disc de pe A pe B sau
de pe A pe C}
begin
t[A]:=t[A]-1;
if (n-k) mod 2=1 then
t[B]:=t[B]+1
else
t[C]:=t[C]+1;
scad(m,unu);
if m<>zero then
begin
if (n-k) mod 2=1 then
begin
aux:=A; A:=C; C:=aux;
n:=k;
end
else
begin
n:=k;
aux:=A; A:=B; B:=C; C:=aux;
end;
end;
end;
until m=zero;
if nrp>1 then
writeln(output);
write(output,t[1],' ',t[2],' ',t[3]);
citire(n,m);
end;
end.
To understand, to the start of the program I calculate (with other program) the 2^k-1 powers. That means that x