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>
#include <math.h>
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define ull unsigned long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
#define len(a) a.size()
#define sz(v) (int)(v.size())
#define pii pair<int,int>
const int N = 2e5 + 1;
const int md = 998244353;
const int mod = 1e9 + 7;
const int mega = 1e6 + 3;
void solve(){
int n;
cin >> n;
int a[n + 1];
int mx = 0;
for(int i = 1; i <= n; ++i)cin >> a[i];
for(int mask = 0; mask < (1 << n); ++mask){
vector<int>vec;
int sum = 0;
for(int i = 0 ; i < n ; ++i){
if(mask >> i & 1){
sum += a[i + 1];
vec.pb(sum);
sum = 0;
}
else{
sum += a[i + 1];
}
}
bool x = true;
for(int i = 1 ; i < vec.size(); ++i){
if(vec[i - 1] > vec[i]){
x = false;
break;
}
}
if(x == true)mx = max(mx , (int)vec.size());
}
cout << mx;
}
signed main(){
SPEED;
int t = 1;
//cin >> t;
while (t--) {
solve();
}
#ifndef ONLINE_JUDGE
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}
Compilation message (stderr)
segments.cpp: In function 'void solve()':
segments.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 1 ; i < vec.size(); ++i){
| ~~^~~~~~~~~~~~
# | 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... |