A9804 | Vitaliy and Pie
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with $n$ room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the ( $n-1$ )-th room to the $n$ -th room. Thus, you can go to room $x$ only from room $x-1$ .
The potato pie is located in the $n$ -th room and Vitaly needs to go there.
Each pair of consecutive rooms has a door between them. In order to go to room $x$ from room $x-1$ , you need to open the door between the rooms with the corresponding key.
In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type $t$ can open the door of type $T$ if and only if $t$ and $T$ are the same letter, written in different cases. For example, key f can open door F.
Each of the first $n-1$ rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.
Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room $n$ .
Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room $n$ , which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The potato pie is located in the $n$ -th room and Vitaly needs to go there.
Each pair of consecutive rooms has a door between them. In order to go to room $x$ from room $x-1$ , you need to open the door between the rooms with the corresponding key.
In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type $t$ can open the door of type $T$ if and only if $t$ and $T$ are the same letter, written in different cases. For example, key f can open door F.
Each of the first $n-1$ rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.
Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room $n$ .
Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room $n$ , which has a delicious potato pie. Write a program that will help Vitaly find out this number.
输入格式
The first line of the input contains a positive integer $n$ ( $2<=n<=10^{5}$ ) — the number of rooms in the house.
The second line of the input contains string $s$ of length $2·n-2$ . Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string $s$ contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position $i$ of the given string $s$ contains a lowercase Latin letter — the type of the key that lies in room number $(i+1)/2$ .
The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position $i$ of the given string $s$ contains an uppercase letter — the type of the door that leads from room $i/2$ to room $i/2+1$ .
The second line of the input contains string $s$ of length $2·n-2$ . Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string $s$ contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position $i$ of the given string $s$ contains a lowercase Latin letter — the type of the key that lies in room number $(i+1)/2$ .
The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position $i$ of the given string $s$ contains an uppercase letter — the type of the door that leads from room $i/2$ to room $i/2+1$ .
输出格式
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room $n$ .
输入输出样例
输入 #1
3 aAbB
输出 #1
0
输入 #2
4 aBaCaB
输出 #2
3
输入 #3
5 xYyXzZaZ
输出 #3
2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted