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

26434번 - Happy Subarrays 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
25 초 (추가 시간 없음) 1024 MB50363675.000%

문제

Let us define $F(B, L, R)$ as the sum of a subarray of an array $B$ bounded by indices $L$ and $R$ (both inclusive). Formally, $F(B, L, R) = B_L + B_{L+1} + \cdots + B_R$.

An array $C$ of length $K$ is called a happy array if all the prefix sums of $C$ are non-negative. Formally, the terms $F(C, 1, 1), F(C, 1, 2), \dots, F(C, 1, K)$ are all non-negative.

Given an array $\mathbf{A}$ of $\mathbf{N}$ integers, find the result of adding the sums of all the happy subarrays in the array $\mathbf{A}$.

입력

The first line of the input gives the number of test cases, $\mathbf{T}$. $\mathbf{T}$ test cases follow.

Each test case begins with one line consisting an integer $\mathbf{N}$ denoting the number of integers in the input array $\mathbf{A}$. Then the next line contains $\mathbf{N}$ integers $\mathbf{A_1}, \mathbf{A_2}, \dots, \mathbf{A_N}$ representing the integers in given input array $\mathbf{A}$.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the result of adding the sums of all happy subarrays in the given input array $\mathbf{A}$.

제한

  • 1ドル \le \mathbf{T} \le 100$.
  • $-800 \le \mathbf{A_i} \le 800,ドル for all $i$.

Test Set 1 (11점)

  • 1ドル \le \mathbf{N} \le 200$.

Test Set 2 (20점)

  • For at most 30 cases:
    • 1ドル \le \mathbf{N} \le 4 \times 10^5$.
  • For the remaining cases:
    • 1ドル \le \mathbf{N} \le 200$.

예제 입력 1

2
5
1 -2 3 -2 4
3
1 0 3

예제 출력 1

Case #1: 14
Case #2: 12

In Sample Case #1, the happy subarrays are $[1], [3], [3, -2], [3, -2, 4],$ and $[4]$ with their respective sums 1,ドル 3, 1, 5,$ and 4ドル$. After adding the sums obtained, the result is 14ドル$.

In Sample Case #2, the happy subarrays are $[1], [1, 0], [1, 0, 3], [0], [0, 3],$ and $[3]$ with their respective sums 1,ドル 1, 4, 0, 3,$ and 3ドル$. After adding the sums obtained, the result is 12ドル$.

힌트

출처

Contest > Google > Kick Start > Google Kick Start 2022 > Round G C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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