Submission #884695

#TimeUsernameProblemLanguageResultExecution timeMemory
884695cocoheartsHacker (BOI15_hac)C++17
100 / 100
44 ms5688 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<db, db>; using vi = vector<int>; using vvi = vector<vi>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define mp make_pair #define f first #define s second // const int MOD = 1e9 + 7; // const int MX = 2e5 + 5; const int INF = 1e9; // const ll INF = 1e18; // not too close to LLONG_MAX // const ld PI = acos((ld)-1); // const int dx[4] = {1, 0, -1, 0}, // dy[4] = {0, 1, 0, -1}; // for every grid problem!! #define sz(x) int(x.size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front #define lb lower_bound #define ub upper_bound #define endl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; constexpr int pct(int x) { return (int)__builtin_popcount(x); } constexpr int bits(int x) { return x == 0 ? 0 : 31 - (int)__builtin_clz(x); } template <typename T, typename... U> void dbgh(const T& t, const U&... u) { cerr << t; ((cerr << " | " << u), ...); cerr << endl; } void setPrec() { cout << fixed << setprecision(15); } void unsyncIO() { cin.tie(0)->sync_with_stdio(0); } void setIn(str s) { freopen(s.c_str(), "r", stdin); } void setOut(str s) { freopen(s.c_str(), "w", stdout); } void setIO(str s = "") { unsyncIO(); setPrec(); cin.exceptions(cin.failbit); if (sz(s)) setIn(s + ".in"), setOut(s + ".out"); } #ifdef LOCAL const int L = 100; #define dbg(...) \ cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \ << ": "; \ dbgh(__VA_ARGS__) #else const int L = 500000; #define dbg(...) #endif int nums[L]; void solve() { int n; cin >> n; F0R(i,n) cin >> nums[i]; int ct = (n+1)/2; int ans = -1*INF; deque<int> myQ; // ind starts at 0 int sum = 0; FOR(ind,n-ct,n) sum += nums[ind%n]; FOR(ind,n-ct,n) { sum += nums[(ind+ct)%n]; sum -= nums[ind]; while (myQ.size()) { if (myQ.back()>sum) myQ.pop_back(); else break; } myQ.push_back(sum); } int total = 0; F0R(ind,n) total += nums[ind]; F0R(ind,n) { ans = max(ans,myQ.front()); sum += nums[(ind+ct)%n]; sum -= nums[ind]; while (myQ.size()) { if (myQ.back()>sum) myQ.pop_back(); else break; } myQ.push_back(sum); int removed = total-sum; if (n%2) { removed += nums[(ind+ct)%n]; } if (myQ.front()==removed) myQ.pop_front(); } cout << ans; } int main() { #ifdef LOCAL // call with -DLOCAL freopen("../input.txt", "r", stdin); freopen("../myoutput.txt", "w", stdout); freopen("../debug.txt", "w", stderr); #else setIO(); #endif solve(); }

Compilation message (stderr)

hac.cpp: In function 'void setIn(str)':
hac.cpp:76:28: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 | void setIn(str s) { freopen(s.c_str(), "r", stdin); }
      |                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hac.cpp: In function 'void setOut(str)':
hac.cpp:77:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 | void setOut(str s) { freopen(s.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...