Submission #1184077

#TimeUsernameProblemLanguageResultExecution timeMemory
1184077KhanhDangBigger segments (IZhO19_segments)C++20
13 / 100
73 ms400 KiB
#include<bits/stdc++.h>
using namespace std;
#define     ll long long
#define    pll pair<ll, ll>
#define    pii pair<int, int>
#define     fi first
#define     se second
#define all(v) (v).begin(), (v).end()
#define Unique(v) sort(all(v)); (v).erase(unique(all(v)), (v).end());
const int N = 21;
ll n, a[N];
int ans;
bool check(int mask) {
    ll x = 0;
    vector<ll> s;
    for (int i = 0; i < n - 1; i++) {
        x += a[i + 1];
        if (mask >> i & 1) {
            s.push_back(x);
            x = 0;
        }
    }
    x += a[n];
    s.push_back(x);
    for (int i = 1; i < s.size(); i++)
        if (s[i - 1] > s[i]) return false;
    return true;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define task "task"
    if (fopen(task".INP", "r")) {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }
    if (fopen("task.INP", "r")) {
        freopen("task.INP", "r", stdin);
        freopen("task.OUT", "w", stdout);
    }
    cin>>n;
    for (int i = 1; i <= n; i++) cin>>a[i];
    for (int mask = 0; mask < (1 << (n - 1)); mask++)
        if (check(mask))
            ans = max(ans, __builtin_popcount(mask) + 1);
    cout<<ans;
    cerr<<setprecision(3)<<fixed<<"Time elapsed: "<< 1.0 * clock() / CLOCKS_PER_SEC <<"s\n";
}

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("task.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
segments.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen("task.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...