提出 #35890265
ソースコード 拡げる
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
const int maxn = 2005;
const int inf = 1e9;
int gcd(int x, int y) {
return y ? gcd(y, x % y) : x;
}
int n, L;
struct node {
int w, x, v;
} a[maxn];
struct frac {
int x, y;
frac(int a, int b) {
x = a, y = b;
int d = gcd(a, b);
x /= d, y /= d;
}
friend bool operator < (const frac &a, const frac &b) {
return a.x * b.y < b.x * a.y;
}
friend bool operator == (const frac &a, const frac &b) {
return a.x * b.y == b.x * a.y;
}
};
struct opt {
frac x;
int w;
opt(frac x = frac(0, 1), int w = 0) : x(x), w(w) {}
} b[maxn * 2];
bool cmp(const node &x, const node &y) {
return x.x < y.x;
}
int main() {
#ifdef DEBUG
freopen("1.in", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> L;
for(int i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].x >> a[i].v;
}
sort(a + 1, a + 1 + n, cmp);
int ans = 0;
for(int i = 1; i <= n; i++) {
int cnt = 0;
int sum = a[i].w;
for(int j = 1; j < i; j++) {
if(a[j].v < a[i].v) {
if(a[i].x == a[j].x) {
b[++cnt] = opt(frac(0, 1), a[j].w);
b[++cnt] = opt(frac(0, 1), -a[j].w);
}
continue;
}
if(a[j].v == a[i].v) {
if(a[i].x == a[j].x) {
sum += a[j].w;
}
continue;
}
b[++cnt] = opt(frac(a[i].x - a[j].x, a[j].v - a[i].v), a[j].w);
b[++cnt] = opt(frac(a[i].x + L - a[j].x, a[j].v - a[i].v), -a[j].w);
}
for(int j = i + 1; j <= n; j++) {
if(a[j].v == a[i].v) {
if(a[i].x + L >= a[j].x) {
sum += a[j].w;
}
continue;
}
if(a[j].v > a[i].v) {
if(a[j].x <= a[i].x + L) {
b[++cnt] = opt(frac(0, 1), a[j].w);
b[++cnt] = opt(frac(a[i].x + L - a[j].x, a[j].v - a[i].v), -a[j].w);
}
continue;
}
frac l = frac(0, 1);
if(a[j].x > a[i].x + L) {
l = frac(a[j].x - a[i].x - L, a[i].v - a[j].v);
}
b[++cnt] = opt(l, a[j].w);
b[++cnt] = opt(frac(a[j].x - a[i].x, a[i].v - a[j].v), -a[j].w);
}
sort(b + 1, b + 1 + cnt, [&](opt x, opt y) {
if(x.x == y.x) {
return x.w > y.w;
}
else {
return x.x < y.x;
}
});
// cout << sum << '\n';
// for(int j = 1; j <= cnt; j++) {
// cout << b[j].x << ' ' << b[j].w << ' ' << b[j].o << '\n';
// }
ans = max(ans, sum);
for(int j = 1; j <= cnt; ) {
int k = j;
while(k <= cnt && b[k].x == b[j].x && (b[k].w >= 0) == (b[j].w >= 0)) {
sum += b[k].w;
k++;
}
// cout << sum << ' ';
ans = max(ans, sum);
j = k;
}
// cout << '\n';
// cout << '\n';
}
cout << ans << '\n';
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
F - Fishing |
| ユーザ |
yanchengzhi |
| 言語 |
C++ (GCC 9.2.1) |
| 得点 |
500 |
| コード長 |
2751 Byte |
| 結果 |
AC |
| 実行時間 |
646 ms |
| メモリ |
3696 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| random_01.txt |
AC |
7 ms |
3636 KiB |
| random_02.txt |
AC |
79 ms |
3640 KiB |
| random_03.txt |
AC |
646 ms |
3632 KiB |
| random_04.txt |
AC |
104 ms |
3604 KiB |
| random_05.txt |
AC |
530 ms |
3652 KiB |
| random_06.txt |
AC |
19 ms |
3648 KiB |
| random_07.txt |
AC |
557 ms |
3652 KiB |
| random_08.txt |
AC |
264 ms |
3660 KiB |
| random_09.txt |
AC |
524 ms |
3696 KiB |
| random_10.txt |
AC |
16 ms |
3608 KiB |
| random_11.txt |
AC |
573 ms |
3612 KiB |
| random_12.txt |
AC |
16 ms |
3644 KiB |
| random_13.txt |
AC |
524 ms |
3660 KiB |
| random_14.txt |
AC |
142 ms |
3556 KiB |
| random_15.txt |
AC |
637 ms |
3648 KiB |
| random_16.txt |
AC |
5 ms |
3616 KiB |
| random_17.txt |
AC |
560 ms |
3600 KiB |
| random_18.txt |
AC |
535 ms |
3616 KiB |
| random_19.txt |
AC |
550 ms |
3664 KiB |
| random_20.txt |
AC |
533 ms |
3564 KiB |
| sample_01.txt |
AC |
3 ms |
3624 KiB |
| sample_02.txt |
AC |
2 ms |
3544 KiB |
| sample_03.txt |
AC |
2 ms |
3576 KiB |