답안 #946906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946906 2024-03-15T07:24:23 Z vjudge1 Bulldozer (JOI17_bulldozer) C++17
0 / 100
2 ms 712 KB
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #include <x86intrin.h>

#include <bits/stdc++.h>
#include <chrono>
#include <random>

// @author: Vlapos

namespace operators
{
	template <typename T1, typename T2>
	std::istream &operator>>(std::istream &in, std::pair<T1, T2> &x)
	{
		in >> x.first >> x.second;
		return in;
	}

	template <typename T1, typename T2>
	std::ostream &operator<<(std::ostream &out, std::pair<T1, T2> x)
	{
		out << x.first << " " << x.second;
		return out;
	}

	template <typename T1>
	std::istream &operator>>(std::istream &in, std::vector<T1> &x)
	{
		for (auto &i : x)
			in >> i;
		return in;
	}

	template <typename T1>
	std::ostream &operator<<(std::ostream &out, std::vector<T1> &x)
	{
		for (auto &i : x)
			out << i << " ";
		return out;
	}

	template <typename T1>
	std::ostream &operator<<(std::ostream &out, std::set<T1> &x)
	{
		for (auto &i : x)
			out << i << " ";
		return out;
	}
}

// name spaces
using namespace std;
using namespace operators;
// end of name spaces

// defines
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define uint unsigned int
#define all(vc) vc.begin(), vc.end()
// end of defines

// usefull stuff

void boost()
{
	ios_base ::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

inline int getbit(int &x, int &bt) { return (x >> bt) & 1; }

const int dx4[4] = {-1, 0, 0, 1};
const int dy4[4] = {0, -1, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy8[8] = {-1, -0, 1, -1, 1, -1, 0, 1};

const ll INF = (1e18) + 500;
const int BIG = (1e9) * 2 + 100;
const int MAXN = (1e5) + 5;
const int MOD7 = (1e9) + 7;
const int MOD9 = (1e9) + 9;
const uint MODFFT = 998244353;

#define int ll

struct segTree
{
	struct Node
	{
		int mxSum = 0, mxPref = 0, mxSuff = 0, sum = 0;
	};
	vector<Node> tree;
	int sz = 0;

	Node merge(Node a, Node b)
	{
		Node res;
		res.sum = a.sum + b.sum;
		res.mxSum = max({a.mxSum, b.mxSum, res.mxSum, a.mxSuff + b.mxPref});
		res.mxPref = max(a.mxPref, a.sum + b.mxPref);
		res.mxSuff = max(b.mxSuff, b.sum + a.mxSuff);
		return res;
	}

	void init(int n)
	{
		sz = 1;
		while (sz < n)
			sz *= 2;
		tree.resize(2 * sz);
	}

	void set(int pos, int val, int v, int lv, int rv)
	{
		if (rv - lv == 1)
		{
			tree[v].mxPref = tree[v].mxSum = tree[v].mxSuff = max(val, 0LL);
			tree[v].sum = val;
			return;
		}
		int m = (lv + rv) >> 1;
		if (pos < m)
			set(pos, val, v * 2 + 1, lv, m);
		else
			set(pos, val, v * 2 + 2, m, rv);
		tree[v] = merge(tree[v * 2 + 1], tree[v * 2 + 2]);
	}

	void set(int pos, int val)
	{
		set(pos, val, 0, 0, sz);
	}
};

struct test
{
	void solve(int testcase)
	{
		boost();

		int n;
		cin >> n;
		vector<pair<pii, int>> els(n);
		cin >> els;

		sort(all(els));

		vector<pair<double, pii>> ks;
		for (int i = 0; i < n; ++i)
			for (int j = i + 1; j < n; ++j)
			{
				double cur = (els[j].f.f - els[i].f.f) ? ((double)els[j].f.s - els[i].f.s) / (els[j].f.f - els[i].f.f) : -BIG;
				ks.pb({cur, {i, j}});
			}
		sort(all(ks));

		// vector<pair<pii, int>> bf;
		// for (int i = 0; i < n; ++i)
		// 	bf.pb({{els[i].f.s, els[i].f.f}, i});
		// sort(all(bf));

		vector<int> pos(n);
		vector<int> cur(n);
		segTree tree;
		tree.init(n);
		for (int i = 0; i < n; ++i)
		{
			pos[i] = i;
			cur[i] = els[i].s;

			// poses[bf[i].s] = i;
			// cur[i] = els[bf[i].s].s;
			tree.set(i, cur[i]);
		}

		int res = tree.tree[0].mxSum;
		vector<pii> HELP;
		for (int i = 0; i <= n; ++i)
		{
			if (i == n or (i != 0 and ks[i].f != ks[i - 1].f))
			{
				for (auto [a, b] : HELP)
				{
					int pa = pos[a];
					int pb = pos[b];

					tree.set(pa, cur[pb]);
					tree.set(pb, cur[pa]);

					swap(cur[pa], cur[pb]);
					pos[a] = pb;
					pos[b] = pa;
				}
				// cout << cur << ": " << tree.tree[0].mxSum << "\n";
				res = max(res, tree.tree[0].mxSum);
			}
			if (i != n)
				HELP.pb(ks[i].s);
		}
		cout << res << '\n';
	}
};

main()
{
	boost();
	int q = 1;
	// cin >> q;
	for (int i = 0; i < q; i++)
	{
		test t;
		t.solve(i);
	}
	return 0;
}
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//
//                                                                                    //
//                               Coded by Der_Vlἀpos                                  //
//                                                                                    //
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]//

Compilation message

bulldozer.cpp:213:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  213 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 712 KB Output is correct
11 Runtime error 1 ms 348 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 712 KB Output is correct
11 Runtime error 1 ms 348 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -