Skip to content

Commit b453e77

Browse files
Add files via upload
1 parent d58dcdf commit b453e77

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <cstdio>
2+
#include <vector>
3+
4+
using namespace std;
5+
6+
#define legal_move(n) (n >= 0 ? true : false)
7+
8+
void precompute(vector <int> &winner, int MAX_GAMES, int k, int l)
9+
{
10+
winner[0] = 2;
11+
12+
for(int i = 1; i < MAX_GAMES; i++)
13+
{
14+
if(winner[i - 1] == 2 || (legal_move(i - k) && winner[i - k] == 2) || (legal_move(i - l) && winner[i - l] == 2))
15+
{
16+
winner[i] = 1;
17+
}
18+
else
19+
{
20+
winner[i] = 2;
21+
}
22+
}
23+
}
24+
25+
int main()
26+
{
27+
const int MAX_GAMES = 1e6 + 1;
28+
vector <int> winner(MAX_GAMES);
29+
int no_of_games, k, l;
30+
scanf("%d %d %d", &k, &l, &no_of_games);
31+
32+
precompute(winner, MAX_GAMES, k, l);
33+
34+
while(no_of_games--)
35+
{
36+
int no_of_coins;
37+
scanf("%d", &no_of_coins);
38+
printf("%c", winner[no_of_coins] == 1 ? 'A' : 'B');
39+
}
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)