So.. I have a solution to a problem but it gives me a error.. Can you tell my what is wrong, please? http://codeforces.net/contest/546/submission/35514636
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
So.. I have a solution to a problem but it gives me a error.. Can you tell my what is wrong, please? http://codeforces.net/contest/546/submission/35514636
Название |
---|
Dear AlexandruOlteanu2017,
You code passed test 1 successfully on my computer when compiled using C++17. Nonetheless, you have declared the global array
dp
as an array of size 2, and accesseddp[2]
inside the main() function. This may cause a run-time error, as you should only accessdp[0]
anddp[1]
. It seems that the C++17 compiler was able to detect and fix the array-index problem.On the other hand, you may check the following C++17 implementation 35517203 for solving the problem.
Hope that this helps.
Best wishes
Thank you very much. That was the problem. :)
With pleasure.
The following is an alternative C++17 solution using queue< int > to store the cards that each player holds.
35519429
Best wishes,
The following is yet another alternative C++17 solution. Instead of using queue< int > to store the cards that each player holds, the card numbers between 1 and 10 are decremented by one to be between 0 and 9. A
long long state
member of each player is then used to store the present cards held by the player as the decimal digits of the variable. Adding/removing a card is implemented using a simple decimal number arithmetic.To check for the presence of cycles in the test case, the initial state before each fight is stored in an STL set. The fight continues until either the number of cards that one of the players holds is 0 or the new state after the fight is found in the set of previous states.
35521757
The following is another alternative C++17 solution using a nested
STL map
to store the visited states, and a two-dimensionaldp[x][count]
array that stores the increment to be added to the present state when card numberx
is added to player who holdscount
cards.35526236