Submission #633166

# Submission time Handle Problem Language Result Execution time Memory
633166 2022-08-21T17:46:33 Z Alma Hacker (BOI15_hac) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
using ll = long long;
using ii = pair<int,int>;

const int INF = 1e9;
const ll LLINF = 1e18;
using vi = vector<int>;
using vvi = vector<vi>;

void setIO (string fileName) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    if (fileName != "std") {
        freopen((fileName + ".in").c_str(), "r", stdin);
        freopen((fileName + ".out").c_str(), "w", stdout);
    }
}

int main() {
    setIO("std");

    int n;
	cin >> n;
	vi a(3*n), p(3*n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[n+i] = a[2*n+i] = a[i];
	}
	p[0] = a[0];
	for (int i = 1; i < 3*n; i++) {
		p[i] = p[i-1] + a[i];
	}
	int ans = 0, h = (n+1) / 2;
	for (int i = n; i < 2*n; i++) {
		if (a[i-1] == a[i+1]) {
			ans = max(ans, p[i] - p[i-h]);
			ans = max(ans, p[i+h-1] - p[i-1]);
		} else if (a[i-1] > a[i+1]) {
			ans = max(ans, p[i+h-1] - p[i-1]);
		} else {
			ans = max(ans, p[i] - p[i-h]);
		}
	}
	cout << ans << '\n';

    return 0;
}

Compilation message

hac.cpp: In function 'void setIO(std::string)':
hac.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((fileName + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -