QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138454#4368. OilPetroTarnavskyi#WA 1ms3584kbC++172.0kb2023-08-11 19:00:582023-08-11 19:01:00

Judging History

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

  • [2023-08-11 19:01:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2023-08-11 19:00:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

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

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

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;
	}
};

bool cmp(pair<Point, int> p1, pair<Point, int> p2) {
	LL prod = p1.first * p2.first;
	if (prod > 0) {
		return true;
	}
	if (prod < 0) {
		return false;
	}
	return p1.second > p2.second;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> x0(n), x1(n), y(n);
	FOR(i, 0, n) {
		cin >> x0[i] >> x1[i] >> y[i];
		if (x0[i] > x1[i]) {
			swap(x0[i], x1[i]);
		}
	}
	LL ans = 0;
	FOR(i, 0, n) {
		FOR(k, 0, 2) {
			Point p(k == 0 ? x0[i] : x1[i], y[i]);
			vector<pair<Point, int>> vecUp, vecDown;
			FOR(j, 0, n) {
				if (y[j] > y[i]) {
					// right plus
					vecUp.emplace_back(Point(x1[j], y[j]) - p, x1[j] - x0[j]);
					// left minus
					vecUp.emplace_back(Point(x0[j], y[j]) - p, x0[j] - x1[j]);
				}
				else if (y[j] < y[i]) {
					// left plus
					vecDown.emplace_back(Point(x0[j], y[j]) - p, x1[j] - x0[j]);
					// right minus
					vecDown.emplace_back(Point(x1[j], y[j]) - p, x0[j] - x1[j]);
				}
			}
			sort(ALL(vecUp), cmp);
			sort(ALL(vecDown), cmp);
			LL cur = x1[i] - x0[i];
			int ptr = 0;
			for (auto [pt, delta] : vecUp) {
				cur += delta;
				while (ptr < SZ(vecDown) && pt * vecDown[ptr].first > 0) {
					cur += vecDown[ptr++].second;
				}
				ans = max(ans, cur);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

詳細信息

Test #1:

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

input:

5
100 180 20
30 60 30
70 110 40
10 40 50
0 80 70

output:

200

result:

ok single line: '200'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

3
50 60 10
-42 -42 20
25 0 10

output:

25

result:

ok single line: '25'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3572kb

input:

1
-100 180 20

output:

0

result:

wrong answer 1st lines differ - expected: '280', found: '0'