比赛 “Asm.Def战记之拉格朗日点”杯 评测结果 AAAETEEAEE
题目名称 Asm.Def的微小贡献 最终得分 40
用户昵称 Derrick_M 运行时间 4.001 s
代码语言 Pascal 内存使用 0.18 MiB
提交时间 2015-11-04 10:43:11
显示代码纯文本
program P2092;
var
  a,id,ansn:array[1..1000] of longint;
  i,n,ans,sum:longint;

procedure swap(var u,v:longint);
var
  tmp:longint;
begin
  tmp:=u;
  u:=v;
  v:=tmp;
end;

procedure qsort(l,r:longint);
var
  i,j,x,y:longint;
begin
  i:=l;
  j:=r;
  x:=a[l+random(r-l+1)];
  repeat
    while a[i]<x do inc(i);
    while x<a[j] do dec(j);
    if not(i>j) then
                begin
                  swap(a[i],a[j]);
                  swap(id[i],id[j]);
                  inc(i);
                  j:=j-1;
                end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;

function dfs(u:longint):boolean;
begin
  if u=n+1 then exit(false);
  if a[u]=sum then
  begin
    inc(ans);
    ansn[ans]:=u;
    exit(true);
  end;
  inc(ans);
  ansn[ans]:=u;
  sum:=sum xor a[u];
  if dfs(u+1) then exit(true);
  sum:=sum xor a[u];
  dec(ans);
  if dfs(u+1) then exit(true);
  exit(false);
end;

procedure solve;
begin
  for i:=2 to n do
    if a[i]=a[i-1] then
    begin
      writeln(2);
      writeln(id[i-1],' ',id[i]);
      exit;
    end;
  sum:=0;
  dfs(1);
  writeln(ans);
  for i:=1 to ans do
    write(id[ansn[i]],' ');
end;

begin
  assign(input,'asm_contribute.in');assign(output,'asm_contribute.out');
  reset(input);rewrite(output);
  randomize;
  readln(n);
  for i:=1 to n do
  begin
    read(a[i]);
    id[i]:=i;
  end;
  qsort(1,n);
  solve;
  close(input);close(output);
end.