A14602 | Rubik's Cube Coloring (hard version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors.
Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?
You have a perfect binary tree of $2^k - 1$ nodes — a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$ . Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow).
Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube.
A picture of Rubik's cube and its 2D map.More formally:
- a white node can not be neighboring with white and yellow nodes;
- a yellow node can not be neighboring with white and yellow nodes;
- a green node can not be neighboring with green and blue nodes;
- a blue node can not be neighboring with green and blue nodes;
- a red node can not be neighboring with red and orange nodes;
- an orange node can not be neighboring with red and orange nodes;
However, there are $n$ special nodes in the tree, colors of which are already chosen.
You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.
The answer may be too large, so output the answer modulo $10^9+7$ .
Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?
You have a perfect binary tree of $2^k - 1$ nodes — a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$ . Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow).
Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube.
A picture of Rubik's cube and its 2D map.More formally:- a white node can not be neighboring with white and yellow nodes;
- a yellow node can not be neighboring with white and yellow nodes;
- a green node can not be neighboring with green and blue nodes;
- a blue node can not be neighboring with green and blue nodes;
- a red node can not be neighboring with red and orange nodes;
- an orange node can not be neighboring with red and orange nodes;
However, there are $n$ special nodes in the tree, colors of which are already chosen.
You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.
The answer may be too large, so output the answer modulo $10^9+7$ .
输入格式
The first line contains the integers $k$ ( $1 \le k \le 60$ ) — the number of levels in the perfect binary tree you need to color.
The second line contains the integer $n$ ( $1 \le n \le \min(2^k - 1, 2000)$ ) — the number of nodes, colors of which are already chosen.
The next $n$ lines contains integer $v$ ( $1 \le v \le 2^k - 1$ ) and string $s$ — the index of the node and the color of the node ( $s$ is one of the white, yellow, green, blue, red and orange).
It is guaranteed that each node $v$ appears in the input at most once.
The second line contains the integer $n$ ( $1 \le n \le \min(2^k - 1, 2000)$ ) — the number of nodes, colors of which are already chosen.
The next $n$ lines contains integer $v$ ( $1 \le v \le 2^k - 1$ ) and string $s$ — the index of the node and the color of the node ( $s$ is one of the white, yellow, green, blue, red and orange).
It is guaranteed that each node $v$ appears in the input at most once.
输出格式
Print one integer — the number of the different colorings modulo $10^9+7$ .
输入输出样例
输入 #1
3 2 5 orange 2 white
输出 #1
1024
输入 #2
2 2 1 white 2 white
输出 #2
0
输入 #3
10 3 1 blue 4 red 5 orange
输出 #3
328925088
In the picture below, you can see one of the correct colorings of the first test example.


C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted