Logo
(追記) (追記ここまで)

28154번 - Space Alignment 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB153585147.664%

문제

You are collaborating with a few other programmers on a coding project. To your horror, you discover that some people have been using tabs to indent code while other people have been using spaces to indent code within the same file. Apparently these people didn't notice that anything was amiss when they did so.

You wish to replace the tabs with spaces so that the file has consistent indenting. Consistent indenting means that for every line at a nesting depth of $k,ドル $k \ge 0,ドル the first non-whitespace character in the line should be preceded by exactly $k \cdot i$ spaces, where $i>0$.

Is it possible to replace each tabs with a fixed number of spaces to repair the file and have consistent indenting?

입력

The first line of input contains a single integer $n$ (2ドル \le n \le 100$), which is the number of lines of code.

Each of the next $n$ lines contains a string, consisting of a sequence of the characters 's' (representing a space) and/or 't' (representing a tab), followed by a single '\{' or '\}'. Each line will have at most 1ドル,000円$ characters.

The first line is guaranteed to be a single '\{', the last line is guaranteed to be a single '\}', and the braces throughout the data are guaranteed to match; that is, looking at only those characters as a single string, it is always possible to repeatedly remove a substring "\{\}" until you are left with the empty string.

출력

Output a single integer, which is the smallest number of spaces greater than zero to replace each tab with and achieve consistent indentation, or $-1$ if it isn't possible.

제한

예제 입력 1

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

예제 출력 1

2

힌트

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2023 K번

  • 문제를 만든 사람: Andy Nguyen
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /