A7924 | Smart Boy
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Once Petya and Vasya invented a new game and called it "Smart Boy". They located a certain set of words — the dictionary — for the game. It is admissible for the dictionary to contain similar words.
The rules of the game are as follows: first the first player chooses any letter (a word as long as $1$ ) from any word from the dictionary and writes it down on a piece of paper. The second player adds some other letter to this one's initial or final position, thus making a word as long as $2$ , then it's the first player's turn again, he adds a letter in the beginning or in the end thus making a word as long as $3$ and so on. But the player mustn't break one condition: the newly created word must be a substring of a word from a dictionary. The player who can't add a letter to the current word without breaking the condition loses.
Also if by the end of a turn a certain string $s$ is written on paper, then the player, whose turn it just has been, gets a number of points according to the formula:
where
-  is a sequence number of symbol $c$ in Latin alphabet, numbered starting from $1$ . For example, , and .
-  is the number of words from the dictionary where the line $s$ occurs as a substring at least once.
Your task is to learn who will win the game and what the final score will be. Every player plays optimally and most of all tries to win, then — to maximize the number of his points, then — to minimize the number of the points of the opponent.
The rules of the game are as follows: first the first player chooses any letter (a word as long as $1$ ) from any word from the dictionary and writes it down on a piece of paper. The second player adds some other letter to this one's initial or final position, thus making a word as long as $2$ , then it's the first player's turn again, he adds a letter in the beginning or in the end thus making a word as long as $3$ and so on. But the player mustn't break one condition: the newly created word must be a substring of a word from a dictionary. The player who can't add a letter to the current word without breaking the condition loses.
Also if by the end of a turn a certain string $s$ is written on paper, then the player, whose turn it just has been, gets a number of points according to the formula:
where
-  is a sequence number of symbol $c$ in Latin alphabet, numbered starting from $1$ . For example, , and .
-  is the number of words from the dictionary where the line $s$ occurs as a substring at least once.
Your task is to learn who will win the game and what the final score will be. Every player plays optimally and most of all tries to win, then — to maximize the number of his points, then — to minimize the number of the points of the opponent.
输入格式
The first input line contains an integer $n$ which is the number of words in the located dictionary $(1<=n<=30)$ . The $n$ lines contain the words from the dictionary — one word is written on one line. Those lines are nonempty, consisting of Latin lower-case characters no longer than $30$ characters. Equal words can be in the list of words.
输出格式
On the first output line print a line "First" or "Second" which means who will win the game. On the second line output the number of points of the first player and the number of points of the second player after the game ends. Separate the numbers by a single space.
输入输出样例
输入 #1
2 aba abac
输出 #1
Second 29 35
输入 #2
3 artem nik max
输出 #2
First 2403 1882
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted