Pagini recente » Cod sursa (job #1924064) | Cod sursa (job #3037836) | Cod sursa (job #1406043) | Cod sursa (job #3037839) | Cod sursa (job #1428840)
program siruri;
var val,s,max,k,j,p,i,n:longint;
nr:array[1..1000000] of longint;
a,v:array[1..1000000] of char;
bufin,bufout:array[1..1 shl 16] of byte;
f,g:text;
function cauta(c:char; st,dr:longint):longint;
var m:longint;
begin
while st<=dr do
begin
m:=(st+dr) div 2;
if c>=a[m] then dr:=m-1
else st:=m+1
end;
cauta:=st;
end;
begin
assign(f,'1-siruri.in'); reset(f);
assign(g,'siruri.out'); rewrite(g);
settextbuf(f,bufin); settextbuf(g,bufout);
readln(f,p);
readln(f,n);
for i:=1 to n do
read(f,v[i]);
if p=1 then
begin
//I'm still working on it!
nr[n]:=1;
s:=1;
for i:=n-1 downto 1 do
begin
nr[i]:=1;
for j:=i+1 to n do
if v[i]<=v[j] then nr[i]:=(nr[i]+nr[j]) mod 41357;
s:=(s+nr[i]) mod 41357;
end;
writeln(g,s);
end
else
begin
k:=1;
a[1]:=v[1];
for i:=2 to n do
begin
j:=cauta(v[i],1,k);
a[j]:=v[i];
if j>k then k:=j;
end;
writeln(g,k);
end;
close(g);
end.