QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235817#4522. Orchard Division / Divide and SelllsantireAC ✓3727ms73528kbC++172.1kb2023-11-03 10:15:152023-11-03 10:15:15

Judging History

This is the latest submission verdict.

  • [2023-11-03 10:15:15]
  • Judged
  • Verdict: AC
  • Time: 3727ms
  • Memory: 73528kb
  • [2023-11-03 10:15:15]
  • Submitted

answer

#include <bits/stdc++.h>
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second

#ifdef ANARAP
//local
#else
//judge
#endif

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
//<key,mapped type,comparator,...>
typedef tree<ii,null_type,less<ii>,rb_tree_tag,
	tree_order_statistics_node_update> indexed_set;
//find_by_order(i) devuelve iterador al i-esimo elemento
//order_of_key(k): devuelve la pos del lower bound de k
//Ej: 12, 100, 505, 1000, 10000.
//order_of_key(10) == 0, order_of_key(100) == 1,
//order_of_key(707) == 3, order_of_key(9999999) == 5

const ll INF = 2e18;

ll solve(vector<ii>& v, int len)
{
	sort(v.begin(), v.end());
	indexed_set s;
	int pos = 0;
	ll ret = INF;
	while(pos < sz(v))
	{
		int from = pos;
		while(pos < sz(v) && v[pos].fst == v[from].fst) s.insert(mp(v[pos++].snd, sz(s)));
		if(sz(s) < sz(v)/2) continue;
		auto ite = s.find_by_order(sz(v)/2-1);
		if(sz(s) > sz(v)/2 && next(ite)->fst == ite->fst) continue;
		ret = min(ret, (1LL+v[from].fst) * (1LL+ite->fst));
	}
	return ret;
}

int main()
{
	// agregar g++ -DANARAP en compilacion
	#ifdef ANARAP
		freopen("input.in", "r", stdin);
		//freopen("output","w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int len,n;
	while(cin >> len >> n)
	{
		vector<ii> v(n);
		forn(i,n) cin >> v[i].fst >> v[i].snd;
		if(n%2)
		{
			cout << "-1\n";
			continue;
		}
		ll ans = solve(v, len);
		forn(i,n) v[i].fst = len-1-v[i].fst;
		ans = min(ans, solve(v, len));
		forn(i,n) v[i].snd = len-1-v[i].snd;
		ans = min(ans, solve(v, len));
		forn(i,n) v[i].fst = len-1-v[i].fst;
		ans = min(ans, solve(v, len));
		if(ans == INF) ans = -1;
		cout << ans << '\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3727ms
memory: 73528kb

input:

2 2
0 0
1 1
3 3
2 0
1 1
0 2
5 4
0 0
0 4
1 1
3 3
1 1
0 0
2 1
0 0
2 1
0 1
2 2
0 0
0 1
2 1
1 0
2 2
0 0
1 0
2 2
0 1
1 0
2 3
0 0
0 1
1 0
2 1
1 1
2 2
0 0
1 1
2 2
0 1
1 1
2 3
0 0
0 1
1 1
2 2
1 0
1 1
2 3
0 0
1 0
1 1
2 3
0 1
1 0
1 1
2 4
0 0
0 1
1 0
1 1
16 128
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11...

output:

1
-1
4
-1
-1
-1
1
-1
1
1
-1
-1
1
1
-1
1
-1
-1
2
112
112
49
200
72
72
72
180
24
36
10
40
24
24
50
10
8
-1
962
644
256
408
480
104
208
1161
1147
200
2925
1715
1344
2850
2772
4784
3844
3843
4770
2200
15370986841276356
2877993933040512
41134990537084484
9427060193835330
203654902990282524
24659767492258...

result:

ok 93 lines