현충일 새벽 3시에 열린 매치..
보통 SRM 은 밤12시 또는 새벽 1시에 열리는데..
SRM 472 는 GCJ 2 라운드의 영향으로 시간이 좀 밀렸다..
이번매치는 250 이 좀 tricky 해서 챌로만 대박을 낼수도있었는데..
하필이면 7번방(19번 시드)에 걸리면서 거의 챌을 할수가 없었다..
틀리는사람도 거의 없는데.. 다들 챌이 어찌나 빠르던지.. -_-;;
운도 지지리도 없지.. ㅠ_ㅠ
Level1 - PotatoGame
Problem Statement
Taro and Hanako like potatoes very much. Today they decided to play Potato Game. Initially there is a box containing n potatoes. Taro and Hanako alternate turns, and Taro goes first. In each turn, the player must eat some potatoes from the box. The number of eaten potatoes must be a power of four, i.e., 1, 4, 16, 64 and so on. The first player who cannot eat a valid number of potatoes loses. Return the name of the winner assuming that they both play optimally.
Definition
Class:
PotatoGame
Method:
theWinner
Parameters:
int
Returns:
string
Method signature:
string theWinner(int n)
(be sure your method is public)
Constraints
-
n will be between 1 and 1,000,000,000 (10^9), inclusive.
Examples
0)
1
Returns: "Taro"
Taro will win if he eats 1 potato in the first turn.
1)
2
Returns: "Hanako"
Taro must eat exactly 1 potato in the first turn. In the second turn, Hanako will eat 1 potato and she will win.
2)
3
Returns: "Taro"
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Taro 와 Hanako 가 게임을 하는데 n 개의 감자가 있고 이중에 4^k 꼴의 개수만큼 가져갈 수 있다..
마지막에 가져가는 사람이 이기는게임.. Taro 가 먼저 시작할 때, 누가 이길까??
처음에 게임이론으로 풀려고하니 상태공간이 너무 커서 당황.. (n 이 최대 10억)
근데 의외로 빨리 푸는 사람이 많아서 그냥 greedy 하게 풀어보았다..
4^k 꼴의 수 중 만들수 있는 가장 큰 수 가져가기..
그러다가 반례 발견..!! 역시.. 이렇게 쉬운문제일리가 없지.. -_-;
그래서 처음 몇단계까지 winning position, losing position 을 mark 해가면서 살펴보니 규칙 발견..
20개 단위로 상태가 반복되는거같아서 대략 다음과 같이 풀었다..~
그러다 나중에 다른사람 코드 보니.. 황당..
5로 나누었을때 나머지가 0 또는 2인지만 검사하면 되는 문제였다.. -_-;;
There are N cards which are initially blank. First, Taro writes a distinct number between 1 and N, inclusive, on the front side of each card. The number he writes on the i-th card is taro[i]. Then, Hanako turns over all the cards and writes a distinct number between 1 and N, inclusive, on the back side of each card. The number she writes on the i-th card is hanako[i]. Now you must determine the number of distinct ways that the N cards can be arranged in a row. The cards can be placed in any order and each card can be oriented so that either its front side or back side is displayed. Two arrangements are considered distinct if the i-th card in the row shows a different number in one arrangement than it does it in the other. Return the number of distinct possible arrangements, modulo 1,000,000,007.
Definition
Class:
TwoSidedCards
Method:
theCount
Parameters:
vector <int>, vector <int>
Returns:
int
Method signature:
int theCount(vector <int> taro, vector <int> hanako)
(be sure your method is public)
Constraints
-
N will be between 1 and 50, inclusive, where N is the number of elements in taro.
-
Each element of taro will be between 1 and N, inclusive.
-
taro will contain no duplicate elements.
-
hanako will contain exactly N elements.
-
Each element of hanako will be between 1 and N, inclusive.
-
hanako will contain no duplicate elements.
Examples
0)
{1, 2, 3}
{1, 3, 2}
Returns: 12
If the front side of each card is displayed, the cards will be (1,2,3), and you can get (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1) by changing the order. If the back side of the second card is displayed, the cards will be (1,3,3), and you can get (1,3,3), (3,1,3), (3,3,1) by changing the order. If the back side of the third card is displayed, the cards will be (1,2,2), and you can get (1,2,2), (2,1,2), (2,2,1) by changing the order. If the back sides of both the second and third cards are displayed, the cards will be (1,3,2), and you can get (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1) by changing the order. In total, there are 12 possibilities: (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1), (1,3,3), (3,1,3), (3,3,1), (1,2,2), (2,1,2), (2,2,1).
1)
{1, 2, 3}
{1, 2, 3}
Returns: 6
You can make 123, 132, 213, 231, 312, 321.
2)
{1, 2}
{2, 1}
Returns: 4
You can make 11, 12, 21, 22.
3)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
to be updated..
Level3 - ColorfulTiles
Problem Statement
Taro likes colorful things, especially colorful tiles. Taro's room is an H x W rectangle divided into 1 x 1 tiles. Each tile is one of the following four colors: red, green, blue or yellow. You are given a vector <string> room. If the j-th character of the i-th element is 'R', 'G', 'B' or 'Y', the color of the tile in the j-th column of the i-th row is red, green, blue or yellow, respectively. He decided to change the color of some tiles so that no two adjacent tiles have the same color. Two tiles are adjacent if they share a side or a corner (so a tile has at most 8 adjacent tiles). He is allowed to change at most K tiles. Return the number of ways to change tiles that satisfies the above conditions, modulo 1,000,000,007. Two ways are considered to be different if there is at least one tile of distinct color.
Definition
Class:
ColorfulTiles
Method:
theCount
Parameters:
vector <string>, int
Returns:
int
Method signature:
int theCount(vector <string> room, int K)
(be sure your method is public)
Constraints
-
room will contain between 1 and 50 elements, inclusive.
-
Each element of room will contain the same number of characters.
-
Each element of room will contain between 1 and 50 characters, inclusive.
-
Each character in room will be 'R', 'G', 'B' or 'Y'.
-
K will be between 0 and the number of characters in room, inclusive.
Examples
0)
{"RG"}
1
Returns: 5
If he doesn't change any tiles, he can make "RG". If he changes the first tile, he can make "BG" or "YG". If he changes the second tile, he can make "RB" or "RY".
1)
{"BY"}
2
Returns: 12
All pairs of different colors are possible.
2)
{"RG",
"GR"}
2
Returns: 8
The eight ways are:
RG RG BY YB BG YG RB RY
BY YB GR GR YR BR GY GB
3)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.