Submission #1092514

# Submission time Handle Problem Language Result Execution time Memory
1092514 2024-09-24T09:38:08 Z quangminh412 Stove (JOI18_stove) C++14
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

/*
  John Watson

  Mua Code nhu mua Florentino !!
*/

#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

const int maxn = 10;

int n;
ll res = 0;
int arr[maxn];

void solve_triangle()
{
	int a = arr[1], b = arr[2], c = arr[3];
	int p = a + b + c;
	ll res = p;
	res = res * (p - 2 * a) * (p - 2 * b) * (p - 2 * c);
	
	if (res % 16 != 0)
	{
		cout << 0 << '\n';
		return;
	}
	res /= 16;
	ll sq = sqrt(res);
	if (sq * sq != res)
	{
		cout << 0 << '\n';
		return;
	}
	cout << sq << '\n';
}

vector<pair<int, int>> circle(int a, int b, int r)
{
	vector<pair<int, int>> v;
	for (int i = a - r; i <= a + r; i++)
	{
		ll tmp = r * r - (i - a) * (i - a);
		ll sq = sqrt(tmp);
		if (sq * sq != tmp) continue;
		
		v.push_back({i, sq + b});
		if (sq != 0) v.push_back({i, -sq + b});
	}
	return v;
}

void generate(int pos, int a, int b, vector<int>& used, vector<pair<int, int>>& points)
{
	if (pos == n)
	{
    	if (a != 0 || b != 0) return;

    	ll area = 0;
    	int nn = points.size();
    	for (int i = 0; i < nn; i++) 
    	{
    	    area += points[i].first * points[(i + 1) % nn].second;
    	    area -= points[i].second * points[(i + 1) % nn].first;
    	}
    	area = abs(area);

    	if (area % 2 != 0) return; 
    	res = max(res, area / 2);
    	return;
	}
	
	for (int i = 1; i <= n; i++)
	{
		if (used[i] == 1) continue;
		
		used[i] = 1;

		vector<pair<int, int>> v = circle(a, b, arr[i]);
		for (pair<int, int> p : v)
		{
			int x = p.first;
			int y = p.second;

			bool c = true;
			for (pair<int, int> pp : points)
				if (x == pp.first && y == pp.second)
					c = false;
			if (!c) continue;
			
			points.push_back({x, y});
			generate(pos + 1, x, y, used, points);
			points.pop_back();
		}
		used[i] = 0;
	}
}

signed main()
{
	if (fopen("test.inp", "r"))
	{
		freopen("test.inp", "r", stdin);
		freopen("test.out", "w", stdout);
	}
	faster();

	cin >> n;
	for (int i = 1; i <= n; i++) cin >> arr[i];
	sort(arr + 1, arr + n + 1);
	int sum = 0;
	for (int i = 1; i < n; i++) sum += arr[i];
	if (sum <= arr[n])
	{
		cout << 0 << '\n';
		return 0;
	}
	
	if (n == 3)
	{
		solve_triangle();
		return 0;
	}
	
	vector<int> used(10, 0);
	vector<pair<int, int>> points;
	generate(0, 0, 0, used, points);
	
	cout << res << '\n';

	return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:106:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |   freopen("test.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:107:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |   freopen("test.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -