• 문제 링크
29994번: Investigating Zeroes and Ones
You find yourself in a mysterious binary world, where an array of N binary digits awaits your scrutiny. Each digit is either a zero or a one, creating a unique pattern across the landscape. Your quest is to uncover the hidden patterns of this binary realm
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
int[][] cache = new int[2][n + 1];
long sum = 0;
for (int i = 1; i <= n; i++) {
if (read() == 1) {
cache[1][i] = cache[0][i - 1] + 1;
cache[0][i] = cache[1][i - 1];
} else {
cache[0][i] = cache[0][i - 1] + 1;
cache[1][i] = cache[1][i - 1];
}
sum += cache[1][i];
}
bw.write(String.valueOf(sum));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 18312 시각 - Brute Force / Java (0) | 2024.02.23 |
---|---|
[백준] 18295 Ants - Brute Force / Java (0) | 2024.02.22 |
[백준] 14767 Flow Shop - Dynamic Programming / Java (0) | 2024.02.20 |
[백준] 7515 Prehistoric Operating Systems - Dynamic Programming / Java (0) | 2024.02.19 |
[백준] 26948 Plankan - Dynamic Programming / Java (0) | 2024.02.18 |
댓글