QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166915 | #6864. Fencing the cows | PPP# | AC ✓ | 13ms | 3752kb | C++17 | 3.2kb | 2023-09-06 20:43:28 | 2023-09-06 20:43:29 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
int mult(int a, int b) {
return (1LL * a * b) % mod;
}
int sub(int a, int b) {
int s = a - b;
if (s < 0) s += mod;
return s;
}
int pw(int a, int b) {
if (b == 0) return 1;
if (b & 1) return mult(a, pw(a, b - 1));
int res = pw(a, b / 2);
return mult(res, res);
}
int sum(int a, int b) {
int s = a + b;
if (s >= mod) s -= mod;
return s;
}
const int maxN = 505;
int x[maxN], y[maxN];
int xb[maxN], yb[maxN];
int n, m;
bool good[maxN][maxN];
int tp(int X, int Y) {
if (X > 0 || (X == 0 && Y > 0)) return -1;
return 1;
}
bool cmp(pair<int,int>& a, pair<int,int>& b) {
int X1 = x[a.second] - x[a.first];
int Y1 = y[a.second] - y[a.first];
int X2 = x[b.second] - x[b.first];
int Y2 = y[b.second] - y[b.first];
if (tp(X1, Y1) != tp(X2, Y2)) return tp(X1, Y1) < tp(X2, Y2);
return 1LL * X1 * Y2 > 1LL * X2 * Y1;
}
bool used[maxN];
int dp[maxN];
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 1; i <= m; i++) {
cin >> xb[i] >> yb[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (x[i] == x[j] && y[i] == y[j]) {
good[i][j] = false;
continue;
}
good[i][j] = true;
for (int k = 1; k <= m; k++) {
if (1LL * (x[j] - x[i]) * (yb[k] - y[i]) <= 1LL * (y[j] - y[i]) * (xb[k] - x[i])) {
good[i][j] = false;
break;
}
}
}
}
vector<pair<int,int>> vec;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (x[i] == x[j] && y[i] == y[j]) continue;
if (good[i][j]) {
vec.emplace_back(i, j);
}
}
}
sort(vec.begin(), vec.end(), cmp);
vector<int> f(n);
iota(f.begin(), f.end(), 1);
sort(f.begin(), f.end(), [&](int a, int b) {
return (x[a] < x[b] || (x[a] == x[b] && y[a] < y[b]));
});
const int INF = 1e9;
int best = 1e9;
for (int i = 0; i < f.size(); i++) {
for (int j = 1; j <= n; j++) {
used[j] = false;
}
for (int j = i; j < f.size(); j++) {
used[f[j]] = true;
dp[f[j]] = INF;
}
dp[f[i]] = 0;
for (auto& it : vec) {
if (used[it.first] && used[it.second]) {
if (it.second == f[i]) {
best = min(best, dp[it.first] + 1);
}
else {
dp[it.second] = min(dp[it.second], dp[it.first] + 1);
}
}
}
}
if (best > 1e8) best = -1;
cout << best << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 3752kb
input:
9 4 1 1 1 1 -1 -1 1 -1 -1 0 0 4 1 1 1 1 -1 -1 1 -1 -1 1 0 500 500 -17 6 -12 -117 29 -279 47 -350 59 -396 62 -403 114 -508 220 -674 222 -676 481 -907 667 -1068 830 -1195 1063 -1347 1125 -1384 1196 -1424 1271 -1462 1430 -1514 1522 -1540 1941 -1579 1996 -1581 2068 -1573 2071 -1572 4138 -4 4143 1 4145 6...
output:
4 -1 36 6 34 -1 77 -1 -1
result:
ok 9 lines