QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#155592#7015. Rikka with IlluminationsPetroTarnavskyiAC ✓438ms3912kbC++173.2kb2023-09-01 20:56:512023-09-01 20:56:52

Judging History

你现在查看的是最新测评结果

  • [2023-09-01 20:56:52]
  • 评测
  • 测评结果:AC
  • 用时:438ms
  • 内存:3912kb
  • [2023-09-01 20:56:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int MAX = 1 << 10;

struct Point
{
	int x, y;
	Point() {}
	Point(int _x, int _y): x(_x), y(_y) {}
	Point operator-(const Point& p) const
	{
		return {x - p.x, y - p.y};
	}
	LL operator*(const Point& p) const
	{
		return (LL)x * p.y - (LL)p.x * y;
	}
};

int n, m;
int l[MAX], r[MAX];
int f[MAX];
pair<int, int> vec[47];
bool used[MAX];

int h(int i, int j)
{
	int sz = 0;
	vec[sz++] = {l[i], -1};
	vec[sz++] = {r[i], 1};
	if (l[i] > r[i])
	{
		vec[sz++] = {n, 1};
		vec[sz++] = {0, -1};
	}
	vec[sz++] = {l[j], 1};
	vec[sz++] = {r[j], -1};
	if (l[j] > r[j])
	{
		vec[sz++] = {n, -1};
		vec[sz++] = {0, 1};
	}
	vec[sz++] = {n, 0};
	sort(vec, vec + sz);
	int bal = 0;
	int s = 0;
	FOR(k, 0, sz)
	{
		if (bal == 1)
		{
			s += vec[k].first - vec[k - 1].first;
		}
		bal += vec[k].second;
	}
	return s;
}

int contains(int i, int x)
{
	if (l[i] < r[i])
		return l[i] <= x && x <= r[i];
	return l[i] <= x || x <= r[i];
}

bool check(VI ans)
{
	FILL(used, 0);
	for(int v : ans)
	{
		for (int j = l[v]; j != r[v]; j = (j + 1) % n)
			used[j] = true;
	}	
	FOR(j, 0, n)
		if(!used[j])
			return 0;
	return 1;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		vector<Point> p(n);
		for (Point& pi : p)
			cin >> pi.x >> pi.y;
		p.push_back(p[0]);
		p.push_back(p[1]);
		
		FILL(l, -1);
		FILL(r, -1);
		FILL(f, -1);
		FOR(i, 0, m)
		{
			Point q;
			cin >> q.x >> q.y;
			FOR(j, 0, n)
			{
				LL prod1 = (p[j + 1] - p[j]) * (q - p[j]);
				LL prod2 = (p[j + 2] - p[j + 1]) * (q - p[j + 1]);
				if (prod1 > 0 && prod2 < 0)
				{
					assert(l[i] == -1);
					l[i] = (j + 1) % n;
				}
				if (prod1 < 0 && prod2 > 0)
				{
					assert(r[i] == -1);
					r[i] = (j + 1) % n;
				}
			}
			assert(l[i] != -1 && r[i] != -1 && l[i] != r[i]);
		}
		//FOR(j, 0, m)
		//	cin >> l[j] >> r[j];
		FOR(i, 0, m)
		{
			int mx = 0;
			FOR(j, 0, m)
			{
				if (l[i] != l[j] && contains(i, l[j]))
				{
					int cur = h(i, j);
					if (cur > mx)
					{
						mx = cur;
						f[i] = j;
					}
				}
			}
			assert(f[i] != i);
		}
		int mn = m + 1, bestV = -1;
		FOR(i, 0, m)
		{
			int v = i;
			int cnt = 1;
			do {
				v = f[v];
				cnt++;
			} while (v != -1 && !contains(v, l[i]));
			if (v != -1 && cnt < mn)
			{
				mn = cnt;
				bestV = i;
			}
		}
		if (bestV == -1)
		{
			VI all(m);
			iota(ALL(all), 0);
			assert(check(all) == 0);
			cout << "-1\n";
		}
		else
		{
			VI ans = {bestV};
			FOR(i, 0, mn - 1)
				ans.PB(f[ans.back()]);
			
			assert(check(ans));
			
			cout << SZ(ans) << "\n";
			FOR(i, 0, SZ(ans))
			{
				if(i != 0)
					cout << " ";
				cout << ans[i] + 1;
			}
			cout << "\n";
		}
	}
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

input:

1
3 3
0 0
1 0
0 1
-1 -1
3 -1
-1 3

output:

2
1 2

result:

ok 1 cases.

Test #2:

score: 0
Accepted
time: 81ms
memory: 3912kb

input:

100
13 17
-976 -766
-628 -956
462 -987
967 -997
981 -123
919 115
847 336
692 789
350 908
-558 996
-843 944
-944 400
-974 -476
-41876798 919231678
-375313647 26070145
-288061228 527643156
-93144407 730297
93699145 -260606010
-393321698 -339399089
644245933 784344503
-731740672 525632046
-32141854 114...

output:

2
1 5
-1
-1
-1
-1
3
5 17 19
-1
4
2 3 5 13
-1
-1
-1
8
2 10 11 8 15 7 3 14
4
5 7 6 8
-1
3
2 7 3
-1
-1
-1
-1
-1
4
2 5 13 8
4
3 12 7 13
4
1 2 5 7
4
13 17 48 25
4
1 56 2 13
5
4 14 6 15 24
37
1 59 42 21 17 83 26 76 38 51 7 20 84 4 9 12 14 32 45 24 78 68 73 67 23 29 11 48 49 27 75 34 88 31 5 40 28
6
2 11 1...

result:

ok 100 cases.

Test #3:

score: 0
Accepted
time: 438ms
memory: 3660kb

input:

100
1000 1000
-206566811 272513
-206555115 -2214957
-206550642 -2598812
-206538524 -3429227
-206534118 -3685047
-206497885 -5342748
-206466348 -6447384
-206454728 -6809307
-206416737 -7877319
-206365268 -9126757
-206352649 -9407755
-206350222 -9460834
-206342491 -9627970
-206253359 -11378633
-206140...

output:

-1
106
1 957 216 416 895 173 254 970 39 812 380 205 653 912 887 125 800 131 362 672 71 562 114 270 481 386 551 806 797 447 267 726 690 843 441 307 431 105 823 103 965 44 748 356 498 298 580 460 660 850 722 695 573 214 282 375 711 683 421 276 30 107 95 561 191 564 413 506 77 836 186 822 11 515 499 88...

result:

ok 100 cases.

Test #4:

score: 0
Accepted
time: 434ms
memory: 3704kb

input:

100
1000 1000
-208687104 -518935
-208658071 -3519412
-208647420 -4102540
-208612602 -5599926
-208458791 -9772885
-208145426 -15035235
-207718591 -20088894
-207636408 -20921257
-207598046 -21298548
-207567860 -21590745
-207181177 -25030716
-206899863 -27258453
-206707452 -28681109
-206631693 -2922191...

output:

461
1 980 684 131 804 527 198 660 616 640 354 450 168 752 963 762 500 754 150 621 841 133 264 416 220 924 919 478 806 392 926 693 633 209 82 253 597 805 219 106 256 663 953 894 334 987 20 815 840 692 329 169 718 594 808 915 698 289 283 899 940 650 139 999 839 191 910 950 845 653 185 541 451 301 530 ...

result:

ok 100 cases.