Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program game;
- var n,i,counter: longint;
- k: array[1..2] of longint;
- a: array[1..2,1..7000] of longint;
- dp, p: array[1..2, 1..7000] of longint;
- function invert(x: longint):longint;
- begin
- if x = 2 then
- x:=1
- else
- x:=2;
- invert:=x;
- end;
- function invert2(x: longint):longint;
- begin
- if x = 1 then
- x:=-1
- else if x = -1 then
- x:=1
- else
- x:=0;
- invert2:=x;
- end;
- function count(x, w: longint):longint;
- var i,c,r: longint;
- f1,f2:boolean;
- begin
- f1:=false;
- f2:=false;
- if p[w][x] = 2 then
- begin
- {writeln(dp[w][x],' ',w,' ',x);}
- count:=dp[w][x];
- exit;
- end
- else if p[w][x] = 1 then
- begin
- {writeln(dp[w][x],' ',w,' ',x);}
- count:=1;
- p[w][x]:=2;
- exit;
- end
- else
- begin
- p[w][x]:=1;
- for i:=1 to k[w] do
- begin
- r:=x + a[w][i];
- if r > n then
- r:= r - n;
- c:=invert2(count(r, invert(w)));
- {if (w = 1) and (x = 8) then
- writeln(c);}
- {writeln(c);}
- if c = 1 then
- begin
- f1:=true;
- break;
- end
- else if c = 0 then
- f2:=true;
- end;
- end;
- p[w][x]:=2;
- if f1 then
- dp[w][x]:=1
- else if f2 then
- dp[w][x]:=0
- else
- dp[w][x]:=-1;
- count:=dp[w][x];
- end;
- BEGIN
- read(n);
- read(k[1]);
- for i:=1 to k[1] do
- read(a[1][i]);
- read(k[2]);
- for i:=1 to k[2] do
- read(a[2][i]);
- dp[1][1]:=-1;
- dp[2][1]:=-1;
- p[1][1]:=2;
- p[2][1]:=2;
- for i:=2 to n do
- begin
- counter:=count(i, 1);
- if counter = 1 then
- write('Win ')
- else if counter = 0 then
- write('Loop ')
- else
- write('Lose ');
- end;
- writeln;
- for i:=2 to n do
- begin
- counter:=count(i, 2);
- if counter = 1 then
- write('Win ')
- else if counter = 0 then
- write('Loop ')
- else
- write('Lose ');
- end;
- END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement