結果

問題 No.703 ゴミ拾い Easy
ユーザー vjudge1
提出日時 2025-03-19 18:19:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,600 bytes
コンパイル時間 1,873 ms
コンパイル使用メモリ 166,716 KB
実行使用メモリ 20,448 KB
最終ジャッジ日時 2025-03-19 18:19:33
合計ジャッジ時間 8,472 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36 RE * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
main.cpp:40:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     for (int i = 1;i <= n;i++) scanf("%lld", &a[i]);
      |                                ~~~~~^~~~~~~~~~~~~~~
main.cpp:41:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |     for (int i = 1;i <= n;i++) scanf("%lld", &x[i]);
      |                                ~~~~~^~~~~~~~~~~~~~~
main.cpp:42:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |     for (int i = 1;i <= n;i++) scanf("%lld", &y[i]);
      |                                ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

/*
address:https://vjudge.net/problem/Yukicoder-703

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3e5 + 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[N << 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 void update(int id, int l, int r, int j) {
        int& i = idl[id];
        if (i == j) return;
        if (cmp(i, j, mid) == j) swap(i, j);
        if (cmp(i, j, l) == j) update(ls, l, mid, j);
        if (cmp(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] };
    for (int i = 1;i <= n;i++) {
        int j = LCSGT.query(1, 0, N - 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, N - 5, i);
    }
    printf("%lld\n", dp[n]);
    return 0;
}
0