Submission #633167

#TimeUsernameProblemLanguageResultExecution timeMemory
633167AlmaHacker (BOI15_hac)C++17
0 / 100
0 ms212 KiB
#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; vector<ll> 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]; } ll 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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...