結果
問題 | No.703 ゴミ拾い Easy |
ユーザー | snrnsidy |
提出日時 | 2023-05-05 11:33:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 109 ms / 1,500 ms |
コード長 | 3,792 bytes |
コンパイル時間 | 3,501 ms |
コンパイル使用メモリ | 358,216 KB |
実行使用メモリ | 12,928 KB |
最終ジャッジ日時 | 2024-11-22 21:16:44 |
合計ジャッジ時間 | 9,310 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,820 KB |
testcase_01 | AC | 5 ms
6,820 KB |
testcase_02 | AC | 4 ms
6,820 KB |
testcase_03 | AC | 4 ms
6,816 KB |
testcase_04 | AC | 4 ms
6,820 KB |
testcase_05 | AC | 4 ms
6,816 KB |
testcase_06 | AC | 5 ms
6,820 KB |
testcase_07 | AC | 5 ms
6,816 KB |
testcase_08 | AC | 5 ms
6,820 KB |
testcase_09 | AC | 4 ms
6,820 KB |
testcase_10 | AC | 4 ms
6,820 KB |
testcase_11 | AC | 5 ms
6,816 KB |
testcase_12 | AC | 4 ms
6,820 KB |
testcase_13 | AC | 4 ms
6,820 KB |
testcase_14 | AC | 7 ms
6,820 KB |
testcase_15 | AC | 6 ms
6,820 KB |
testcase_16 | AC | 6 ms
6,820 KB |
testcase_17 | AC | 5 ms
6,816 KB |
testcase_18 | AC | 5 ms
6,824 KB |
testcase_19 | AC | 5 ms
6,820 KB |
testcase_20 | AC | 5 ms
5,760 KB |
testcase_21 | AC | 5 ms
5,760 KB |
testcase_22 | AC | 5 ms
5,888 KB |
testcase_23 | AC | 5 ms
5,888 KB |
testcase_24 | AC | 109 ms
12,800 KB |
testcase_25 | AC | 85 ms
12,928 KB |
testcase_26 | AC | 83 ms
12,768 KB |
testcase_27 | AC | 82 ms
12,796 KB |
testcase_28 | AC | 82 ms
12,900 KB |
testcase_29 | AC | 85 ms
12,928 KB |
testcase_30 | AC | 85 ms
12,768 KB |
testcase_31 | AC | 83 ms
12,896 KB |
testcase_32 | AC | 81 ms
12,864 KB |
testcase_33 | AC | 87 ms
12,928 KB |
testcase_34 | AC | 74 ms
12,800 KB |
testcase_35 | AC | 73 ms
12,672 KB |
testcase_36 | AC | 73 ms
12,892 KB |
testcase_37 | AC | 74 ms
12,800 KB |
testcase_38 | AC | 72 ms
12,768 KB |
testcase_39 | AC | 73 ms
12,800 KB |
testcase_40 | AC | 72 ms
12,928 KB |
testcase_41 | AC | 72 ms
12,764 KB |
testcase_42 | AC | 73 ms
12,780 KB |
testcase_43 | AC | 73 ms
12,896 KB |
testcase_44 | AC | 3 ms
5,888 KB |
testcase_45 | AC | 4 ms
5,888 KB |
testcase_46 | AC | 84 ms
12,800 KB |
testcase_47 | AC | 83 ms
12,828 KB |
testcase_48 | AC | 4 ms
5,888 KB |
testcase_49 | AC | 3 ms
5,888 KB |
コンパイルメッセージ
In member function 'void CHT::add(int, lint)', inlined from 'int main()' at main.cpp:119:9: main.cpp:81:44: warning: 'cht.CHT::p' is used uninitialized [-Wuninitialized] 81 | while (v.size() >= p + 2 && chk(v[v.size() - 2], v.back(), pi(x, y))) { | ^ main.cpp: In function 'int main()': main.cpp:114:13: note: 'cht' declared here 114 | CHT cht; | ^~~
ソースコード
#pragma GCC optimize("O3") #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long lint; typedef long double llf; typedef pair<lint, lint> pi; struct line { long long int a, b; }; class CHT { public: vector<pi> v; int p; lint query(lint x) { if (v.empty()) return 1e18; while (p + 1 < v.size() && v[p].first * x + v[p].second > v[p + 1].first * x + v[p + 1].second) p++; return v[p].first * x + v[p].second; } bool chk(pi a, pi b, pi c) { return 1ll * (b.first - a.first) * (b.second - c.second) < (c.first - b.first) * (a.second - b.second); } void add(int x, lint y) { if (!v.empty() && v.back().first == x) { if (v.back().second < y) return; v.pop_back(); } while (v.size() >= p + 2 && chk(v[v.size() - 2], v.back(), pi(x, y))) { v.pop_back(); } v.emplace_back(x, y); } void clear() { v.clear(); } }; long long int dp[300005]; long long int a[300005]; long long int x[300005]; long long int y[300005]; int n; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for(int i=1;i<=n;i++) cin >> a[i]; for(int i=1;i<=n;i++) cin >> x[i]; for(int i=1;i<=n;i++) cin >> y[i]; fill(dp, dp + 300005, 1e18); dp[0] = 0; //dp[i] = min(0<=j<i) dp[j] + a[i]^2 - 2*x[j+1]*a[i] + x[j+1]^2 + y[j+1]^2 // A[i] = -2*x[i] , B[j] = a[j+1] , C[j] = dp[j] + x[j+1]^2 + y[j+1]^2, D[i] = a[i]^2 CHT cht; line ins; ins.a = -x[1]; ins.b = dp[0] + x[1]*x[1] + y[1]*y[1]; //tree.insert(-1e12,1e12,x[1],dp[0] + x[1]*x[1] + y[1]*y[1]); cht.add(ins.a,ins.b); for (int i = 1; i <= n; i++) { //cout << cht.query2(B*i) + (B * ((i * (i + 1)) / 2)) - (A * i) << '\n'; dp[i] = cht.query(2*a[i]) + a[i]*a[i]; cht.add(-x[i+1],dp[i] + x[i+1]*x[i+1] + y[i+1]*y[i+1]); //tree.insert(-1e12,1e12,x[i+1],dp[i] + x[i+1]*x[i+1] + y[i+1]*y[i+1]); } cout << dp[n] << '\n'; return 0; }