Skip to content

Commit fc73cd2

Browse files
committed
[Silver I] Title: IOIOI, Time: 248 ms, Memory: 20148 KB, Score: 100 point -BaekjoonHub
1 parent 4400342 commit fc73cd2

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

백준/Silver/5525. IOIOI/IOIOI.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,40 @@ public static void main(String[] args) throws IOException {
1414
S = br.readLine();
1515

1616
int answer = 0;
17-
17+
int currentLength = 0;
18+
boolean oTime= false;
19+
boolean iTime = true;
1820
for(int i =0; i<S.length(); i++) {
19-
if(S.charAt(i) == 'I') {
20-
if(check(i)) {
21-
answer+=1;
22-
}
23-
}
24-
}
25-
26-
System.out.println(answer);
27-
}
28-
static boolean check(int startIndex) {
29-
int oCount = 0;
30-
31-
int maxLength = N*2 +1;
32-
boolean checking = true;
33-
for(int i = startIndex; i< startIndex+ maxLength; i++) {
34-
if(i > S.length()-1) {
35-
checking = false;
36-
break;
21+
if(iTime && !oTime && S.charAt(i) =='I') {
22+
currentLength+=1;
23+
iTime = false;
24+
oTime = true;
3725
}
38-
if(i != startIndex &&i > 0 && S.charAt(i) == S.charAt(i-1)) {
39-
checking = false;
40-
break;
26+
else if(!iTime && oTime && S.charAt(i) == 'O') {
27+
currentLength+=1;
28+
iTime = true;
29+
oTime = false;
4130
}
42-
if(S.charAt(i) == 'O') {
43-
oCount+=1;
31+
else {
32+
if(currentLength >= N*2+1) {
33+
answer += (currentLength - (2*N+1)) / 2 + 1;
34+
}
35+
if(S.charAt(i) == 'I') {
36+
currentLength = 1;
37+
iTime = false;
38+
oTime = true;
39+
} else {
40+
currentLength = 0;
41+
iTime = true;
42+
oTime = false;
43+
}
4444
}
4545
}
4646

47-
if(oCount == N && checking) {
48-
return true;
47+
if(currentLength >= N*2+1) {
48+
answer += (currentLength - (2*N+1)) / 2 + 1;
4949
}
50-
return false;
50+
51+
System.out.println(answer);
5152
}
52-
}
53+
}

백준/Silver/5525. IOIOI/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 14420 KB, 시간: 140 ms
7+
메모리: 20148 KB, 시간: 248 ms
88

99
### 분류
1010

1111
문자열
1212

1313
### 제출 일자
1414

15-
2025년 1월 7일 14:18:00
15+
2025년 1월 7일 14:58:41
1616

1717
### 문제 설명
1818

0 commit comments

Comments
 (0)