QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#703748#9434. Italian CuisineMiguel03121WA 0ms3576kbC++172.4kb2024-11-02 18:24:432024-11-02 18:24:44

Judging History

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

  • [2024-11-02 18:24:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3576kb
  • [2024-11-02 18:24:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define F(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) x.begin(), x.end()
#define IOS ios_base::sync_with_stdio(0)

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;

struct point {
  ll x, y;
};

bool isValid(point &p1, point &p2, bool shouldBeNegative, ll radius) {
  double a, b, c;
  if (p1.x == p2.x) {
    a = -1, b = 0, c = p1.x;
  } else {
    a = (double)(p2.y - p1.y) / (p2.x - p1.x);
    b = -1;
    c = (double)(p1.y * p2.x - p2.y * p1.x) / (p2.x - p1.x);
  }
  double dSq = c * c / (a * a + b * b), x = -(a * c) / (a * a + b * b),
         y = -(b * c) / (a * a + b * b);
  double norm = sqrt(x * x + y * y);
  x /= norm, y /= norm;
  double x2 = p2.x - p1.x, y2 = p2.y - p1.y;
  bool negative = (x * y2 - x2 * y < 0);

  return negative == shouldBeNegative && dSq >= radius * radius;
}

ll solve(vector<point> &points, bool shouldBeNegative, ll radius) {
  int n = points.size();
  vector<ll> ps(n + 1);
  F(i, 0, n) {
    ps[i + 1] = ps[i] + points[i].x * points[(i + 1) % n].y -
                points[i].y * points[(i + 1) % n].x;
  }
  ll ans = 0;

  F(i, 0, n) {
    int l = 2, right = n - 1;
    while (l < right) {
      int mid = (l + right) / 2;
      // cout << i << ' ' << mid << ' ' << l << ' ' << right << endl;
      if (!isValid(points[i], points[(mid + i) % n], shouldBeNegative,
                   radius)) {
        right = mid;
      } else {
        l = mid + 1;
      }
    }

    l = (i + l) % n;
    if (!isValid(points[i], points[l], shouldBeNegative, radius)) {
      l = (l + n - 1) % n;
    }

    ll tmp =
        ps[l] - ps[i] + points[l].x * points[i].y - points[l].y * points[i].x;
    if (l < i) {
      tmp = ps[n] + tmp;
    }
    // cout << i << ' ' << l << ' ' << tmp << endl;
    ans = max(ans, tmp);
  }

  return ans;
}

int main() {
  int t, n;
  cin >> t;

  while (t--) {
    cin >> n;

    ll xc, yc, radius;
    cin >> xc >> yc >> radius;
    vector<point> points(n);
    point center;
    center.x = center.y = 0;

    F(i, 0, n) {
      cin >> points[i].x >> points[i].y;
      points[i].x -= xc, points[i].y -= yc;
    }

    ll ans = solve(points, false, radius);
    reverse(ALL(points));
    // ans = max(ans, solve(points, false, radius));
    cout << ans << '\n';
  }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3460kb

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

5
24
0

result:

ok 3 number(s): "5 24 0"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3576kb

input:

1
6
0 0 499999993
197878055 -535013568
696616963 -535013568
696616963 40162440
696616963 499999993
-499999993 499999993
-499999993 -535013568

output:

286862654137719264

result:

wrong answer 1st numbers differ - expected: '0', found: '286862654137719264'