Submission #1270610

#TimeUsernameProblemLanguageResultExecution timeMemory
1270610BuiDucManh123Hacker (BOI15_hac)C++20
0 / 100
65 ms61380 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define taskname ""
#define ld long double
const int mod = 1e9+7;
using namespace std;
#define int ll
int n, a[500009], f[500009][29];
int query(int l, int r){
    int z = r - l + 1;
    int cnt = 0;
    while((1 << cnt) <= z){
        cnt++;
    }
    cnt--;
    return min(f[l][cnt], f[r - (1 << cnt) + 1][cnt]);
}
signed main() {
    if (fopen(taskname".inp","r")) {
        freopen(taskname".inp","r",stdin);
        freopen(taskname".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = n + 1; i <= 2 * n; i++){
        a[i] = a[i - n];
    }
    int cnt = (n + 1) / 2;
    for(int i = 1; i <= 2 * n; i++){
        a[i] += a[i - 1];
    }
    for(int i = n + 1; i <= 2 * n; i++){
        f[i][0] = a[i] - a[i - cnt];
    }
    for(int i = 1; i < 20; i++){
        for(int j = n + 1; j <= 2 * n; j++){
            if(j + (1 << i) <= 2 * n){
                f[j][i] = min(f[j][i - 1], f[j + (1 << (i - 1))][i - 1]);
            }
        }
    }
    int ans = 0;
    for(int i = n + 1; i <= 2 * n; i++){
        ans = max(ans, query(i - cnt + 1, i));
    }
    cout << ans;
    return 0;
}

Compilation message (stderr)

hac.cpp: In function 'int main()':
hac.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(taskname".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(taskname".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...