记录编号 |
48270 |
评测结果 |
WWWWWWWWWW |
题目名称 |
奇怪的监狱 |
最终得分 |
0 |
用户昵称 |
Abel·S |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
0.003 s |
提交时间 |
2012-11-05 13:23:35 |
内存使用 |
0.18 MiB |
显示代码纯文本
program cojs_p929;
type
pri=array[0..1001] of longint;
var
pos,dis,p:pri;
n,m,i,j,k,sum:longint;
procedure ass;
begin
assign(input,'prison.in');
assign(output,'prison.out');
reset(input);
rewrite(output);
end;
procedure cls;
begin
close(input);
close(output);
end;
procedure swap(var a,b:longint);
var
t:longint;
begin
t:=a;
a:=b;
b:=t;
end;
procedure sort1(l,r:longint; var a:pri);
var
i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then begin swap(a[i],a[j]); inc(i); dec(j); end;
until i>j;
if i<r then sort1(i,r,a);
if l<j then sort1(l,j,a);
end;
procedure sort2(l,r:longint; var a,b:pri);
var
i,j,x:longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then begin swap(a[i],a[j]); swap(b[i],b[j]); inc(i); dec(j); end;
until i>j;
if i<r then sort2(i,r,a,b);
if l<j then sort2(l,j,a,b);
end;
procedure init;
var
i:longint;
begin
ass;
readln(n,m);
pos[0]:=0;
fillchar(p,sizeof(p),0);
p[0]:=2;
p[n+1]:=2;
for i:=1 to m do
begin
read(pos[i]);
p[pos[i]]:=1;
end;
sort1(1,m,pos);
for i:=1 to m do
dis[i]:=pos[i]-pos[i-1]-1;
dis[m+1]:=n-pos[m];
pos[m+1]:=n+1;
sort2(1,m+1,dis,pos);
end;
begin
init;
sum:=0;
for i:=m+1 downto 2 do
begin
sum:=sum+(dis[i]*(m+1-i+1));
p[pos[i]]:=2;
if pos[i]<m then begin j:=pos[i]+1;
while p[j]<2 do begin inc(sum,p[j]); inc(j); end; end;
if pos[i]>0 then begin j:=pos[i]-1;
while p[j]<2 do begin inc(sum,p[j]); dec(j); end; end;
end;
sum:=sum+dis[1]*m;
writeln(sum);
end.