結果
| 問題 |
No.703 ゴミ拾い Easy
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-03-21 17:05:35 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 130 ms / 1,500 ms |
| コード長 | 1,839 bytes |
| コンパイル時間 | 3,861 ms |
| コンパイル使用メモリ | 278,556 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2025-03-21 17:05:45 |
| 合計ジャッジ時間 | 9,266 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:46:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:47:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
47 | for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:48:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | for (int i = 1; i <= n; i++) scanf("%lld", &y[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
/*
address:https://vjudge.net/problem/Yukicoder-703
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3e5 + 5;
const int V = 1e5 + 5;
struct line {
LL k, b;
}li[N];
struct LiChaoSegmentTree {
#define ls (id << 1)
#define rs (id << 1 | 1)
#define mid (l + r >> 1)
int idl[V << 2];
inline int cmp(int i, int j, int x) {
LL y0 = li[i].k * x + li[i].b, y1 = li[j].k * x + li[j].b;
if (y0 < y1) return i;
else return j;
}
inline int cmp1(int i, int j, int x) {
LL y0 = li[i].k * x + li[i].b, y1 = li[j].k * x + li[j].b;
if (y0 <= y1) return i;
else return j;
}
inline void update(int id, int l, int r, int j) {
int &i = idl[id];
if (i == j) return;
if (cmp1(i, j, mid) == j) swap(i, j);
if (cmp1(i, j, l) == j) update(ls, l, mid, j);
if (cmp1(i, j, r) == j) update(rs, mid + 1, r, j);
}
inline int query(int id, int l, int r, int x) {
if (l == r) return idl[id];
int ret = x <= mid ? query(ls, l, mid, x) : query(rs, mid + 1, r, x);
return cmp(ret, idl[id], x);
}
}LCSGT;
int n;
LL a[N], x[N], y[N];
LL dp[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
for (int i = 1; i <= n; i++) scanf("%lld", &y[i]);
li[0] = { -2 * x[1], x[1] * x[1] + y[1] * y[1] };
LCSGT.update(1, 0, V - 5, 0);
for (int i = 1; i <= n; i++) {
int j = LCSGT.query(1, 0, V - 5, a[i]);
dp[i] = a[i] * a[i] + x[j + 1] * x[j + 1] + y[j + 1] * y[j + 1] - 2 * x[j + 1] * a[i] + dp[j];
li[i] = { -2 * x[i + 1], dp[i] + x[i + 1] * x[i + 1] + y[i + 1] * y[i + 1] };
LCSGT.update(1, 0, V - 5, i);
}
printf("%lld\n", dp[n]);
return 0;
}
vjudge1