본문 바로가기

Prefix Sums4

[codility] MinAvgTwoSlice MinAvgTwoSlice MinAvgTwoSliceFind the minimal average of any slice containing at least two elements.Task Score100%Correctness100%Performance100% correctness 100%에 performance 20%인 코드..솔직히 이중 for문 넣으면서 시간초과 나올거란건 예상했다 ㅎㅎ..나올 수 있는 모든 경우의 수를 다 배열에 넣어서 하나하나 다 값을 비교했다. 항상 느끼는거지만 이렇게 설명하면서 왜 점수가 낮게 나오는지 충분히 알게되는 것 같다.ㅋㅋ x// you can also use imports, for example:// import java.util.*;​// you can write .. 2018. 5. 24.
[codility] GenomicRangeQuery GenomicRangeQuery GenomicRangeQueryFind the minimal nucleotide from a range of sequence DNA.Task Score62%Correctness100%Performance0% 오늘도 시작은 correctness 100%에 performance 0% ^^~! 제일 작은 문자를 넣어서 숫자로 바꿔주었다. 오늘도 이중포문이 문제인가~ 하고 이중포문을 없애주려고 방법을 바꿔봤다. ​x// you can also use imports, for example:// import java.util.*;​// you can write to stdout for debugging purposes, e.g.// System.out.println("this is .. 2018. 5. 24.
[codility] PassingCars PassingCars PassingCarsCount the number of passing cars on the road.Task Score100%Correctness100%Performance100% 자동차가 지나갈 때마다 짝을짓는데 (0인경우, 1인경우) 이렇게 짝을 짓는다. 그런데 앞의 0인 경우보다 앞에 등장한 차는 짝을 짓지 않는다. For example, consider array A such that: A[0] = 0 A[1] = 1 A[2] = 0 A[3] = 1 A[4] = 1We have five pairs of passing cars: (0, 1), (0, 3), (0, 4), (2, 3), (2, 4). 그래서 그냥 하나씩 짝을 지어줄 필요 없이 count하는 식으로 했다.0이 한번.. 2018. 5. 23.
[codility] CountDiv CountDiv CountDivCompute number of integers divisible by k in range [a..b].Task Score100%Correctness100%Performance100% A가 0이면 그냥 B를 K로 나눈 몫에 1을 더해주면 개수가 나온다.그런데 A가 0이 아니면 B 전에 나오는 K의 배수의 개수에서 A 이전에 나오는 K의 배수들을 빼줘야한다. 원래 (B / K +1) - ((A - 1) / K + 1) 인데 앞 뒤의 1이 서로 상쇄되므로 생략해주었다. x// you can also use imports, for example:// import java.util.*;​// you can write to stdout for debugging purposes, e... 2018. 5. 23.