Submission #145610

# Submission time Handle Problem Language Result Execution time Memory
145610 2019-08-20T13:45:48 Z dolphingarlic Hacker (BOI15_hac) C++14
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
#pragma GCC Optimize("O3")
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
 
ll a[500000];
pair<ll, ll> sums[500000];
 
int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    FOR(i, 0, n) cin >> a[i];
 
    ll window = (n + 1) / 2, sum = 0;
    FOR(i, 0, window) sum += a[i];
    FOR(i, 0, n) {
        sums[i] = {sum, i};
        sum += a[(i + window) % n] - a[i];
    }
 
    sort(sums, sums + n);
 
    ll curr_start = sums[0].second, rotation = window;
    FOR(i, 1, n) {
        if (sums[i].second == (curr_start + rotation) % n) {
            cout << sums[i].first << '\n';
            break;
        } else {
            if ((curr_start + rotation) % n > sums[i].second) {
                rotation = (sums[i].second - curr_start + n) % n + window;
            } else {
                rotation = (curr_start - sums[i].second + n) % n + rotation;
                curr_start = sums[i].second;
            }

            if (rotation >= n) {
                cout << sums[i].first << '\n';
                break;
            }
        }
    }
    return 0;
}

Compilation message

hac.cpp:2:0: warning: ignoring #pragma GCC Optimize [-Wunknown-pragmas]
 #pragma GCC Optimize("O3")
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -