문제: app.codility.com/programmers/lessons/6-sorting/number_of_disc_intersections/
int result = 0;
int[] start = new int[A.Length];
int[] end = new int[A.Length];
int t = A.Length - 1;
for (int i = 0; i < A.Length; i++)
{
int s = i > A[i] ? i - A[i] : 0;
int e = t - i > A[i] ? i + A[i] : t;
start[s]++;
end[e]++;
}
t = 0;
for (int i = 0; i < A.Length; i++)
{
if (start[i] > 0)
{
result += t * start[i];
result += start[i] * (start[i] - 1) / 2;
if (10000000 < result) return -1;
t += start[i];
}
t -= end[i];
}
return result;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson7. Brackets (C#) (0) | 2020.11.20 |
---|---|
[Codility] Lesson6. Triangle (C#) (0) | 2020.11.20 |
[Codility] Lesson6. MaxProductOfThree (C#) (0) | 2020.11.20 |
[Codility] Lesson6. Distinct (C#) (0) | 2020.11.20 |
[Codility] Lesson5. PassingCars (C#) (0) | 2020.11.17 |