QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155481#7015. Rikka with IlluminationsPetroTarnavskyi#WA 14ms3596kbC++172.5kb2023-09-01 17:54:382023-09-01 17:54:40

Judging History

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

  • [2023-09-01 17:54:40]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:3596kb
  • [2023-09-01 17:54:38]
  • 提交

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;

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 main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		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]);
		vector<pair<pair<int, int>, int>> seg(m, MP(MP(-1, -1), -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(seg[i].F.F == -1);
					seg[i].F.F = (j + 1) % n;
				}
				if (prod1 < 0 && prod2 > 0)
				{
					assert(seg[i].S == -1);
					seg[i].F.S = j + 1;
				}
			}
			seg[i].S = i;
			assert(seg[i].F.F != -1 && seg[i].F.S != -1 && seg[i].F.F != seg[i].F.S);
		}
		sort(ALL(seg));
		vector<int> best;
		FOR(i, 0, m)
		{
			if (seg[i].F.F < seg[i].F.S && seg[i].F.F != 0)
				continue;
			int end = seg[i].F.F > seg[i].F.S ? seg[i].F.F : n;
			vector<int> idxes = {seg[i].S};
			int cur = seg[i].F.S;
			int mx = -1, mxIndex;
			bool ok = false;
			FOR(j, 0, m)
			{
				if (j == i || seg[j].F.F > seg[j].F.S)
					continue;
				if (seg[j].F.F <= cur)
				{
					if (seg[j].F.S > mx)
					{
						mx = seg[j].F.S;
						mxIndex = seg[j].S;
					}
					if (mx >= end)
					{
						idxes.push_back(mxIndex);
						ok = true;
						break;
					}
				}
				else if (seg[j].F.F > mx)
				{
					break;
				}
				else
				{
					idxes.push_back(mxIndex);
					cur = mx;
					mx = -1;
					j--;
				}
			}
			if (ok && (best.empty() || SZ(idxes) < SZ(best)))
				best = idxes;
		}
		if (best.empty())
		{
			cout << "-1\n";
		}
		else
		{
			cout << SZ(best) << "\n";
			for (int i : best)
			{
				cout << i + 1 << " ";
			}
			cout << "\n";
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2
2 3 

result:

ok 1 cases.

Test #2:

score: -100
Wrong Answer
time: 14ms
memory: 3596kb

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
10 1 
-1
-1
-1
-1
3
17 19 5 
-1
4
5 13 27 3 
-1
-1
-1
8
11 8 15 7 3 14 2 10 
-1
-1
3
7 3 2 
-1
-1
-1
-1
-1
4
13 8 2 5 
4
7 13 3 6 
4
4 5 7 1 
4
13 17 48 25 
4
15 1 56 2 
5
34 37 40 14 25 
37
39 90 58 8 35 22 18 33 44 71 83 26 76 38 51 7 20 84 4 9 12 14 32 45 24 78 68 73 67 23 29 11 48 49 85 75 34 ...

result:

wrong output format Expected EOLN