結果
問題 | No.703 ゴミ拾い Easy |
ユーザー |
![]() |
提出日時 | 2019-03-16 18:07:46 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 108 ms / 1,500 ms |
コード長 | 2,050 bytes |
コンパイル時間 | 974 ms |
コンパイル使用メモリ | 90,080 KB |
実行使用メモリ | 13,292 KB |
最終ジャッジ日時 | 2025-01-02 14:07:35 |
合計ジャッジ時間 | 5,380 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 46 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:72:45: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll*’ {aka ‘long long int*’} [-Wformat=] 72 | for (int i = 1; i <= n; i++)scanf("%d", a + i); | ~^ ~~~~~ | | | | int* ll* {aka long long int*} | %lld main.cpp:73:45: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 73 | for (int i = 1; i <= n; i++)scanf("%d", &xy[i].first); | ~^ ~~~~~~~~~~~~ | | | | | long long int* | int* | %lld main.cpp:74:45: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 74 | for (int i = 1; i <= n; i++)scanf("%d", &xy[i].second); | ~^ ~~~~~~~~~~~~~ | | | | | long long int* | int* | %lld main.cpp:72:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 72 | for (int i = 1; i <= n; i++)scanf("%d", a + i); | ~~~~~^~~~~~~~~~~~~ main.cpp:73:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 73 | for
ソースコード
#include <iostream> #include <algorithm> #include <cstring> #include <sstream> #include <map> #include <queue> #include <set> #include <vector> #include <stack> #include <cstdio> #include <cmath> #include <bitset> #define mk make_pair #define pb push_back using namespace std; typedef long long int ll; typedef pair<ll, ll> pos; const ll MOD = 1234567, N = 300010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838; const int S = 60; ll mn(ll a, ll b) { if (a == -1)return b; if (b == -1)return a; return min(a, b); } static ll gcd(ll v1, ll v2) { if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2); } ll pw(ll v1, ll v2) { ll v3 = 1; while (v2 > 0) { if (v2 % 2)v3 = (v3*v1) % MOD; v1 = (v1*v1) % MOD; v2 /= 2; } return v3; } ll n, a[N],dp[N]; pos xy[N]; struct ConvexHullTrick { std::deque<std::pair<long long, long long> > dq; //(傾き、切片) void add(long long a, long long b) { std::pair<long long, long long> p0 = std::make_pair(a, b); while (dq.size() >= 2) { int sz = dq.size(); std::pair<long long, long long> p1 = dq[sz - 1]; std::pair<long long, long long> p2 = dq[sz - 2]; if ((p0.second - p1.second)*(p0.first - p2.first) < (p0.second - p2.second)*(p0.first - p1.first))break;//交点のx座標を比較 dq.pop_back(); } dq.push_back(p0); } long long query(long long x) { while (dq.size() >= 2) { long long v1 = dq[0].first*x + dq[0].second; long long v2 = dq[1].first*x + dq[1].second; if (v1 <= v2)break; dq.pop_front(); } return dq[0].first*x + dq[0].second; } }; ConvexHullTrick cht; int main() { cin >> n; for (int i = 1; i <= n; i++)scanf("%d", a + i); for (int i = 1; i <= n; i++)scanf("%d", &xy[i].first); for (int i = 1; i <= n; i++)scanf("%d", &xy[i].second); for (int i = 1; i <= n; i++) { cht.add(-2*xy[i].first, dp[i - 1] + xy[i].first*xy[i].first + xy[i].second*xy[i].second); dp[i] = a[i] * a[i] + cht.query(a[i]); } cout << dp[n] << endl; return 0; }