이 문제의 조건들이 있다
- each letter of the string is either painted in exactly one color (red or green) or isn't painted;
- each two letters which are painted in the same color are different;
- the number of letters painted in red is equal to the number of letters painted in green;
- the number of painted letters of this coloring is maximum among all colorings of the string which meet the first three conditions.
요약하면
- 색깔은 red or green
- 같은색으로 칠해진 두 수는 다르다
- 그 수들 총 갯수는 똑같다
이렇게 하면 풀이방법
색이 두개이고 중복되는 값드이 들어가면 안되는 것이니 set을 사용
그리고 set.find해서 이것이 존재하지 않는다면 end()로 반환되니 해당 단어를 set에 넣어주면된다
string str; cin >> str;
for (auto a : str) {
//존재하지않는다
if (s[0].find(a) == s[0].end()) {
s[0].insert(a);
}
else if (s[1].find(a) == s[1].end()) {
s[1].insert(a);
}
}
이 방법에서 그린이든, 빨강이든 갯수는 다를 수 있는데 같게 하려면 마지막에 사이를 더한 후 /2를 하면된다
틀린이유 :
set을 사용한다는 접근 방법이 떠오르지않았다
'코드포스 > div3' 카테고리의 다른 글
B. Alphabetical Strings (0) | 2021.08.09 |
---|---|
A. Shortest Path with Obstacle (0) | 2021.08.09 |
B2. Wonderful Coloring - 2 (0) | 2021.08.05 |