Submission #612362

# Submission time Handle Problem Language Result Execution time Memory
612362 2022-07-29T13:27:16 Z cheissmart Seesaw (JOI22_seesaw) C++14
67 / 100
991 ms 1048576 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
typedef long double db;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, N = 2e5 + 6;
const ll oo = 1e18;

int a[N];
ll p[N];

signed main()
{
	IO_OP;

	cout << fixed << setprecision(12);

	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		p[i] = p[i - 1] + a[i];
	}
	auto go = [&] (int i, int j) {
		return db(p[j] - p[i - 1]) / (j - i + 1);
	};
	V<pair<db, db>> aux;
	for(int len = 1; len <= n; len++) {
		for(int i = 1; i + len - 1 <= n; i++) {
			int j = i + len - 1;
			db he = go(i, j);
			db be = j + 1 <= n ? go(i + 1, j + 1) : oo;
			aux.EB(he, be);
		}
	}
	sort(ALL(aux));
	db tt = go(1, n), ans = oo;
	for(auto[he, be]:aux) {
		ans = min(ans, tt - he);
		tt = max(tt, be);
	}
	cout << ans << '\n';

}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:64:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |  for(auto[he, be]:aux) {
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 520 ms 66104 KB Output is correct
9 Correct 507 ms 66112 KB Output is correct
10 Correct 562 ms 66172 KB Output is correct
11 Correct 540 ms 66088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 2 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 520 ms 66104 KB Output is correct
9 Correct 507 ms 66112 KB Output is correct
10 Correct 562 ms 66172 KB Output is correct
11 Correct 540 ms 66088 KB Output is correct
12 Runtime error 991 ms 1048576 KB Execution killed with signal 9
13 Halted 0 ms 0 KB -