Submission #639125

# Submission time Handle Problem Language Result Execution time Memory
639125 2022-09-08T16:15:47 Z SharpEdged Hacker (BOI15_hac) C++17
100 / 100
52 ms 15644 KB
#include <bits/stdc++.h>

using namespace std;
 
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define LSB(x) ((x) & -(x))
#define sz(x) (int)(x.size())
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define __lcm(a, b) ((a) * (b)) / __gcd(a, b)
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[DEBUG] "<<__func__<<": "<<__LINE__<<", [" << #x << "] = ["; _print(x);
#else
#define dbg(x...)
#endif
 
 
struct Data {
	int r1, c1, r2, c2, d;
	Data(int _r1, int _c1, int _r2, int _c2, int _d) : r1(_r1), c1(_c1), r2(_r2), c2(_c2), d(_d) {};
	bool operator== (const Data& b) const {
		return r1 == b.r1 && r2 == b.r2 && c1 == b.c1 && c2 == b.c2 && d == b.d;
	}
};
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    
    size_t operator()(string x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        uint64_t res = 0;
        for (int i = 0; i < sz(x); i++){
			res ^= x[i] + FIXED_RANDOM;
			res = splitmix64(res);
		}
        return res;
    }
    
    size_t operator()(Data x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		uint64_t res = ((splitmix64(x.r1) ^ splitmix64(splitmix64(x.c1) + FIXED_RANDOM)) ^ splitmix64(splitmix64(x.r2) ^ (splitmix64(splitmix64(x.c2)) ^ x.d))) + FIXED_RANDOM;
		return res;
	}
};
 
const ll MOD = 998244353;
const ll INFLL = 1e18 + 5;
const int INF = 1e9 + 5;
 
char nl = '\n';
 
ll modPow(ll n, ll k){
	if (k == 0) return 1;
	ll res = modPow(n, k / 2);
	res = res * res % MOD;
	if (k & 1) return res * n % MOD;
	return res;
}

bool ccw(pair<ll, ll> p1, pair<ll, ll> p2, pair<ll, ll> p3){
	ll val = (p1.f * p2.s - p1.s * p2.f + p2.f * p3.s - p2.s * p3.f + p3.f * p1.s - p3.s * p1.f);
	if  (val <= 0) return 1;
	return 0;
}

const int mxN = 1e5+5;

void TestCase(){
	int n; cin >> n;
	vector<int> v(2*n);
	int tot = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		tot += v[i];
		v[i + n] = v[i];
	}
	int h = (n+1)/2, o = n - h;
	vector<int> pref(2*n); pref[0] = v[0];
	for (int i = 0; i < 2*n; i++) pref[i] = (i > 0 ? pref[i-1] : 0) + v[i];
	vector<int> sum(2*n);
	deque<pair<int, int>> dq;
	for (int i = 0; i + o - 1 < 2*n; i++){
		sum[i] = pref[i + o - 1] - ((i > 0) ? pref[i-1] : 0);
		if (i > 0 && i + o - 1 < n){
			while (!dq.empty() && dq.back().s <= sum[i]) dq.pop_back();
			dq.push_back({i, sum[i]});
		}
	}
	int ans = -1;
	for (int i = 0; i < n; i++){
		ckmax(ans, tot - dq.front().s);
		if (!dq.empty() && dq.front().f == i+1) dq.pop_front();
		pair<int, int> cur = {i+n-o+1, sum[i+n-o+1]};
		while (!dq.empty() && dq.back().s <= cur.s) dq.pop_back();
		dq.push_back(cur);
	}
	cout << ans << nl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	// cin >> T;
	while (T--){
		TestCase();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 472 KB Output is correct
4 Correct 9 ms 2580 KB Output is correct
5 Correct 21 ms 5836 KB Output is correct
6 Correct 28 ms 7264 KB Output is correct
7 Correct 30 ms 8680 KB Output is correct
8 Correct 52 ms 14156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 328 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 0 ms 320 KB Output is correct
33 Correct 0 ms 220 KB Output is correct
34 Correct 1 ms 472 KB Output is correct
35 Correct 9 ms 2580 KB Output is correct
36 Correct 21 ms 5836 KB Output is correct
37 Correct 28 ms 7264 KB Output is correct
38 Correct 30 ms 8680 KB Output is correct
39 Correct 52 ms 14156 KB Output is correct
40 Correct 2 ms 588 KB Output is correct
41 Correct 3 ms 852 KB Output is correct
42 Correct 4 ms 1108 KB Output is correct
43 Correct 22 ms 5848 KB Output is correct
44 Correct 52 ms 14220 KB Output is correct
45 Correct 11 ms 3028 KB Output is correct
46 Correct 31 ms 8588 KB Output is correct
47 Correct 52 ms 14216 KB Output is correct
48 Correct 43 ms 14412 KB Output is correct
49 Correct 39 ms 15644 KB Output is correct
50 Correct 38 ms 15620 KB Output is correct