比赛 Asm_Def战记之透明计算网络 评测结果 WTWTTTTWTT
题目名称 Asm_Def排兵布阵 最终得分 0
用户昵称 typhon 运行时间 7.664 s
代码语言 Pascal 内存使用 65.01 MiB
提交时间 2015-11-01 11:59:19
显示代码纯文本
  1. var a:array[1..4000000] of boolean;
  2. x:array[1..4000000] of longint;
  3. y:array[1..4000000] of longint;
  4. num:array[1..4000000] of longint;
  5. last:array[1..4000000] of longint;
  6. n,i,u,j,s:longint;total:qword;
  7.  
  8. function dizheng:boolean;
  9. var i,j:longint;
  10. begin
  11. for i:=1 to n-1 do
  12. for j:=i to n do
  13. if last[i]>last[j] then exit(false);
  14. exit(true);
  15. end;
  16. procedure print;
  17. var i,a,b:longint;r,t,w:string;v:boolean;
  18.  
  19. begin
  20. fillchar(last,sizeof(last),0);
  21. v:=true;
  22. for i:=1 to n do
  23. for j:=s downto 1 do
  24. if x[j]=i then begin last[i]:=j;break;end;
  25. if dizheng then total:=total+1;
  26.  
  27. end;
  28.  
  29. procedure try(i:longint);
  30. var j:longint;
  31. begin
  32. for j:=1 to s do
  33. if a[j]=true then begin
  34. x[i]:=y[j];
  35. a[j]:=false;
  36. if i<s
  37. then try(i+1)
  38. else print;
  39. a[j]:=true;
  40. end;
  41. end;
  42. procedure same;
  43. begin
  44. for i:=1 to n do
  45. if num[1]<>1 then exit;
  46. writeln(1);
  47. halt;
  48. end;
  49.  
  50.  
  51. begin
  52. assign(input,'asm_formation.in');
  53. reset(input);
  54. assign(output,'asm_formation.out');
  55. rewrite(output);
  56.  
  57. total:=0;readln(n);
  58. for i:=1 to n do begin
  59. read(num[i]); s:=s+num[i]; end;
  60. u:=1;
  61. same;
  62. { for i:=1 to n do
  63. begin
  64. for j:=1 to num[i] do
  65. y[u]:=i;
  66. u:=u+1;
  67. end; }
  68. for i:=1 to n do
  69. for j:=1 to num[i] do
  70. begin
  71. y[u]:=i;
  72. u:=u+1;
  73. end;
  74. for i:=1 to s do
  75. a[i]:=true;
  76. try(1);
  77. total:=total div 4;
  78. total:=total mod 998244353;
  79. writeln(total);
  80. close(input);
  81. close(output);
  82. end.