# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336857 | boykut | Bigger segments (IZhO19_segments) | C++14 | 40 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define linl long long
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector < int > a(n);
for (int & to : a) {
cin >> to;
}
int max = 0;
if (n <= 20) {
for (int i = 0; i < (1 << (n - 1)); i++) {
vector < int > mas(n, 0);
mas[0] = 0;
int num = i, index = n - 1;
while (num) {
mas[index] = num % 2;
num /= 2;
index--;
}
//for (int to : mas) cout << to; cout << '\n';
bool ok = true;
for (int i = 0; i < n - 1 && ok; i++) {
if (mas[i] == 1 && mas[i + 1] == 1) {
ok = false;
}
}
if (ok == false) continue;
vector < int64_t > vec;
int64_t sum = 0ll;
bool ans = true;
for (int i = 0; i < n; i++) {
if (mas[i] == 1) {
if (!vec.empty()) {
if (sum < vec.back())
ans = false;
}
vec.push_back(sum);
sum = 0;
}
sum += a[i];
}
if (!vec.empty()) {
if (sum < vec.back())
ans = false;
}
vec.push_back(sum);
if (ans && vec.size() > max)
max = vec.size();
}
cout << max << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |