-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2694.cpp
50 lines (45 loc) · 1.06 KB
/
2694.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N; cin >> N;
int arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
if (i) arr[i] += arr[i-1];
}
for (int start_length = 0; start_length < N; start_length++) {
int value = arr[start_length];
if (arr[N-1]%value) continue;
int l = start_length+1;
int cnt = 0;
bool yes = true;
while (l+cnt < N) {
int cur = arr[l+cnt]-arr[l-1];
if (cur>value) {
yes = false;
break;
}
if (cur == value) {
l += cnt+1;
cnt = 0;
} else {
cnt++;
if (l+cnt==N) yes=false;
}
}
if (yes) {
cout << value;
return;
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T; cin >> T; while(T--){
solve();
cout << '\n';
}
return 0;
}