QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#155536 | #7015. Rikka with Illuminations | PetroTarnavskyi# | WA | 73ms | 3644kb | C++17 | 2.8kb | 2023-09-01 19:06:21 | 2023-09-01 19:06:21 |
Judging History
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];
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];
}
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(i, 0, m)
{
int mx = 0;
FOR(j, 0, m)
{
if (contains(i, l[j]))
{
int cur = h(i, j);
if (cur > mx)
{
mx = cur;
f[i] = j;
}
}
}
}
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)
{
cout << "-1\n";
}
else
{
cout << mn << "\n";
int v = bestV;
FOR(i, 0, mn)
{
if (i != 0)
cout << " ";
cout << v + 1;
v = f[v];
}
cout << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3644kb
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: -100
Wrong Answer
time: 73ms
memory: 3608kb
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 2 2 18 2 3 2 2 2 5 -1 2 2 19 2 3 16 2 4 5 -1 2 2 8 -1 8 2 10 11 8 15 7 3 14 2 1 5 -1 3 2 7 3 2 2 4 -1 -1 2 3 4 2 4 11 2 17 5 4 3 12 7 13 4 1 2 5 7 4 13 17 48 25 4 1 56 2 13 2 31 2 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 2 4 1...
result:
wrong answer In case 2, there is no solution but output yes.