Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.54 KB | None | 0 0
  1. program game;
  2. var n,i,counter: longint;
  3.     k: array[1..2] of longint;
  4.     a: array[1..2,1..7000] of longint;
  5.     dp, p: array[1..2, 1..7000] of longint;
  6. function invert(x: longint):longint;
  7. begin
  8. if x = 2 then
  9. x:=1
  10. else
  11. x:=2;
  12. invert:=x;
  13. end;
  14. function invert2(x: longint):longint;
  15. begin
  16. if x = 1 then
  17. x:=-1
  18. else if x = -1 then
  19. x:=1
  20. else
  21. x:=0;
  22. invert2:=x;
  23. end;
  24. function count(x, w: longint):longint;
  25. var i,c,r: longint;
  26.     f1,f2:boolean;
  27. begin
  28. f1:=false;
  29. f2:=false;
  30. if p[w][x] = 2 then
  31. begin
  32. {writeln(dp[w][x],' ',w,' ',x);}
  33. count:=dp[w][x];
  34. exit;
  35. end
  36. else if p[w][x] = 1 then
  37. begin
  38. {writeln(dp[w][x],' ',w,' ',x);}
  39. count:=1;
  40. p[w][x]:=2;
  41. exit;
  42. end
  43. else
  44. begin
  45. p[w][x]:=1;
  46. for i:=1 to k[w] do
  47. begin
  48. r:=x + a[w][i];
  49. if r > n then
  50. r:= r - n;
  51. c:=invert2(count(r, invert(w)));
  52. {if (w = 1) and (x = 8) then
  53. writeln(c);}
  54. {writeln(c);}
  55. if c = 1 then
  56. begin
  57. f1:=true;
  58. break;
  59. end
  60. else if c = 0 then
  61. f2:=true;
  62. end;
  63. end;
  64. p[w][x]:=2;
  65. if f1 then
  66. dp[w][x]:=1
  67. else if f2 then
  68. dp[w][x]:=0
  69. else
  70. dp[w][x]:=-1;
  71. count:=dp[w][x];
  72. end;
  73. BEGIN
  74. read(n);
  75. read(k[1]);
  76. for i:=1 to k[1] do
  77. read(a[1][i]);
  78. read(k[2]);
  79. for i:=1 to k[2] do
  80. read(a[2][i]);
  81. dp[1][1]:=-1;
  82. dp[2][1]:=-1;
  83. p[1][1]:=2;
  84. p[2][1]:=2;
  85. for i:=2 to n do
  86. begin
  87. counter:=count(i, 1);
  88. if counter = 1 then
  89. write('Win ')
  90. else if counter = 0 then
  91. write('Loop ')
  92. else
  93. write('Lose ');
  94. end;
  95. writeln;
  96. for i:=2 to n do
  97. begin
  98. counter:=count(i, 2);
  99. if counter = 1 then
  100. write('Win ')
  101. else if counter = 0 then
  102. write('Loop ')
  103. else
  104. write('Lose ');
  105. end;
  106. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement