Vitaliy and PieTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d & Amp %i64u Submit Status Practice codeforces 525A
Description
After a hard day Vitaly got very hungry and he wants the eat his favorite potato pie. But it's not so simple. Vitaly is in the first, the house with N room located in a line and numbered starting from one on left to right. Y ou can go from the first hostel to the second, from the second-to-the-third and so-on-you can go from the ( n -1)-th room to The n -th. Thus, can go to Room x only from Room x -1.
The potato pie is located in the n-th, and Vitaly needs to go there.
Each pair of consecutive rooms have a door between them. In order to go to room x from room x -1, you need to open the door between the room s with the corresponding key.
All the House have several types of doors (represented by uppercase Latin letters) and several types of keys (Represen Ted 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 this vitaly can use to get to NEX T rooms. Once the door is open with some key, Vitaly won ' t get the key from the keyhole but he'll immediately run into the next R Oom. In the other words, each key can open no more than one door.
Vitaly realizes that he could end up in some and without the key that opens the door to the next. Before the start his run for the potato pie Vitaly can buy any number of the keys in any of the type that's guaranteed to get to Roo M n.
Given The plan of the House, Vitaly wants to know what's the minimum number of keys he needs to buy to surely get to the Class n, which has a delicious potato pie. Write a program, that would help Vitaly, find out, this number.
Input
The first line of the input contains a positive integer n (2≤ n ≤105)-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 Span class= "apple-converted-space" > 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 the class 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 iof the given string s contains an uppercase Letter-the t Ype of the door that leads from the hostel i /2 to the 2 + 1.
Output
Print the only integer-the minimum number of keys this Vitaly needs to buy to surely get from the hostel one to the hostel n.
Sample Input
Input
3 AAbB
Output
0
Input
4 Abacab
Output
3
Input
5 Xyyxzzaz
Output
2
Key: Note that the keys can only be used once, just beginning CE, did not knock the head file Stdio .... Then re, the array opens small ... Then WA, I foolishly use bit arithmetic, this water problem wrong 4 times ...
Code:
#include <iostream>#include<cstring>#include<cmath>#include<algorithm>#include<cstdio>using namespacestd;Const intMAXN =500010;CharS[MAXN];intkey[ -];intMain () {intN; while(~SCANF ("%d", &N)) { intKY =0, Nu =0; scanf ("%s", s); intLen =strlen (s); memset (Key,0,sizeof(key)); for(inti =0; i < Len; i++){ if(S[i] >='A'&& S[i] <='Z'){ if(Key[s[i]-'A'] >0) {Key[s[i]-'A']--; } Elsenu++; } Else if(S[i] >='a'&& S[i] <='Z') {Key[s[i]-'a']++; }} printf ("%d\n", NU); } return 0;}
Vitaliy and Pie (analog)