讨论 / why i can't AC?
koukou 2013-07-03 07:19:00
点我顶贴 收藏 删除
program necklace;

{$mode objfpc}{$H+}

var

a:array[1..500000] of integer;

n,q:longint; c:integer;

procedure init;

var i:longint;

begin

assign(input,'necklace.in');

assign(output,'necklace.out');

reset(input);

rewrite(output);

readln(n,c);

for i:=1 to n do read(a[i]);

readln(q);

end;

procedure rr(k:longint);

var i:longint; x:integer; b:array[1..500000] of integer;

begin

for i:=1 to n-k do

b[k+i]:=a[i];

for i:=n-k+1 to n do

b[i-n+k]:=a[i];

for i:=1 to n do a[i]:=b[i];

end;

procedure ff;

var

i:longint; x:integer;

begin

for i:=2 to ((n+1) shr 1) do

begin

x:=a[i];a[i]:=a[n-i+2]; a[n-i+2]:=x;

end;

end;

procedure ss(i,j:longint);

var x:integer;

begin

x:=a[i];a[i]:=a[j];a[j]:=x;

end;

procedure pp(i,j,k:longint);

var ii:longint;

begin

if i<=j then for ii:=i to j do a[ii]:=k

else

begin for ii:=i to n do a[ii]:=k;

for ii:=1 to j do a[ii]:=k;

end;

end;

procedure cc;

var s,ii:longint;

begin

s:=1;

for ii:=2 to n do

if a[ii]<>a[ii-1] then inc(s);

if a[n]=a[1] then dec(s);

writeln(s);

end;

procedure cs(i,j:longint);

var ii,s:longint;

begin

s:=1;

if i<=j then begin for ii:=i+1 to j do

if a[ii]<>a[ii-1] then inc(s) end

else begin

for ii:=i+1 to n do

if a[ii]<>a[ii-1] then inc(s);

for ii:=2 to j do if a[ii]<>a[ii-1] then inc(s);

if a[1]=a[n] then dec(s);

end;

writeln(s);

end;

procedure move;

var i:longint; x:string; t,y,z:integer;

begin

for i:=1 to q do

begin

readln(x);

if x[1]='R' then begin val(x[3],t); rr(t);end else

if x[1]='F' then ff else

if x[1]='S' then begin val(x[3],t); val(x[5],y); ss(t,y); end else

if x[1]='P' then begin val(x[3],t); val(x[5],y); val(x[7],z);pp(t,y,z);end

else

if (x[1]='C') and (length(x)=1) then cc else

if (x[2]='S') AND (X[1]='C') then begin val(x[3],t); val(x[5],y); cs(t,y);

end;

end;

end;

procedure close1;

begin

close(input);

close(output);

end;

begin

init;

move;

close1;

end.

#1 王以翀1@2013-11-01 00:26:09
回复 删除
超时还是案错?
查看更多回复
提交回复