记录编号 14700 评测结果 AAAAAAAAAAA
题目名称 [USACO Oct09] 乳草的入侵 最终得分 100
用户昵称 GravatarHamster 是否通过 通过
代码语言 Pascal 运行时间 0.075 s
提交时间 2009-11-03 15:03:16 内存使用 0.12 MiB
显示代码纯文本
  1. program milkweed;
  2. var
  3. i,j,x,y,xx,yy,p,time:integer;
  4. a:array[0..101,0..101]of char;
  5. begin
  6. assign(input,'milkweed.in');
  7. assign(output,'milkweed.out');
  8. reset(input);
  9. rewrite(output);
  10. readln(x,y,xx,yy);
  11. yy:=y-yy+1;
  12. for i:=0 to 101 do
  13. for j:=0 to 101 do
  14. a[i,j]:='*';
  15. for i:=1 to y do
  16. begin
  17. for j:=1 to x do
  18. read(a[i,j]);
  19. readln;
  20. end;
  21. a[yy,xx]:='m';
  22. time:=0;
  23. while true do
  24. begin
  25. p:=0;
  26. time:=time+1;
  27. for i:=1 to y do
  28. for j:=1 to x do
  29. begin
  30. if a[i,j]='m' then begin
  31. if a[i-1,j]='.' then begin
  32. a[i-1,j]:='x';
  33. p:=1;
  34. end;
  35. if a[i-1,j-1]='.' then begin
  36. a[i-1,j-1]:='x';
  37. p:=1;
  38. end;
  39. if a[i-1,j+1]='.' then begin
  40. a[i-1,j+1]:='x';
  41. p:=1;
  42. end;
  43. if a[i+1,j]='.' then begin
  44. a[i+1,j]:='x';
  45. p:=1;
  46. end;
  47. if a[i+1,j-1]='.' then begin
  48. a[i+1,j-1]:='x';
  49. p:=1;
  50. end;
  51. if a[i+1,j+1]='.' then begin
  52. a[i+1,j+1]:='x';
  53. p:=1;
  54. end;
  55. if a[i,j-1]='.' then begin
  56. a[i,j-1]:='x';
  57. p:=1;
  58. end;
  59. if a[i,j+1]='.' then begin
  60. a[i,j+1]:='x';
  61. p:=1;
  62. end;
  63. end;
  64. end;
  65. for i:=1 to y do
  66. for j:=1 to x do
  67. if a[i,j]='x' then a[i,j]:='m';
  68. if p=0 then break;
  69. end;
  70. p:=0;
  71. for i:=1 to y do
  72. for j:=1 to x do
  73. if a[i,j]='.' then p:=1;
  74. if p=1 then writeln(-1) else writeln(time-1);
  75. close(input);
  76. close(output);
  77. end.