Submission #1304131

#TimeUsernameProblemLanguageResultExecution timeMemory
1304131vestonvestonBuilding Bridges (CEOI17_building)C++20
100 / 100
65 ms65432 KiB
#include <bits/stdc++.h> #define name "vestonluvto" const char* namein = name ".inp"; const char* nameout = name ".out"; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mod ((1ll) << 31) - 1; #define mod1 ((1ll) << 61) - 1; #define PI 3.141592653589793238462 #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() using namespace std; #ifndef LOCAL #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(int t) {cerr << t;} void _print(long long t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(long double t) {cerr << t;} void _print(double t) {cerr << t;} void _print(unsigned long long t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} void homefix(){ #ifndef LOCAL freopen("fixcode.txt", "w", stderr); #endif } void home(){ homefix(); if (fopen(namein, "r")) { freopen(namein, "r", stdin); freopen(nameout, "w", stdout); } } const int MAXN = 1e6 + 5; int n; long long h[MAXN]; long long w[MAXN]; void nhap(){ cin >> n; for(int i = 1; i <= n; i++)cin >> h[i]; for(int i = 1; i <= n; i++)cin >> w[i]; } struct line{ long long a, b; line(): a(0), b(0) {} line(long long A, long long B): a(A), b(B) {} long long tinh(long long x){ return a*x + b; } }; struct LICHAOTREE{ vector<line> tr; int n; LICHAOTREE(int N): n(N) { tr.resize(N*4 + 5, line(0, LLONG_MAX)); } void update(line f, int l, int r, int id){ if(l == r){ if(f.tinh(l) < tr[id].tinh(l))tr[id] = f; return; } int mid = (l+r)/2; if(f.tinh(mid) < tr[id].tinh(mid))swap(f, tr[id]); if(f.tinh(l) < tr[id].tinh(l))update(f, l, mid, id*2); if(f.tinh(r) < tr[id].tinh(r))update(f, mid+1, r, id*2+1); } long long get(int x, int l, int r, int id){ if(l == r)return tr[id].tinh(l); int mid = (l+r)/2; if(x <= mid)return min(tr[id].tinh(x), get(x, l, mid, id*2)); return min(tr[id].tinh(x), get(x, mid+1, r, id*2+1)); } void up(long long b, long long a){ update(line(a, b), 1, n, 1); } long long g(int x){ return get(x, 1, n, 1); } }; void bfsolve(){} long long dp[MAXN]; void solve(){bfsolve(); LICHAOTREE tree(MAXN); tree.up(h[1]*h[1] - w[1], -2*h[1]); dp[1] = -w[1]; for(int i = 2; i <= n; i++){ dp[i] = h[i]*h[i] - w[i] + tree.g(h[i]); tree.up(dp[i] + h[i]*h[i], -2*h[i]); } for(int i = 1; i <= n; i++)dp[n] += w[i]; cout << dp[n]; } int main(){ fastio(); home();int t = 1; //cin >> t; while(t--)nhap(), solve(); return 0; } /* ___________ ╔══╗ ▐▀▄ ▄▀▌ ▄▄▄▄▄▄▄ / \ ╚╗╔╝ ▌▒▒▀▄▄▄▄▄▀▒▒▐▄▀▀▒██▒██▒▀▀ / MEO \ ╔╝(¯’v´¯) ▐▒▒▒▒▀▒▀▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \ ╚══’.¸. ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▒▒▒▒▒▒▒▒▒▒▒▒▀▄ \ __________ / ╔♫═╗╔╗ kitten ▀█▒▒▒█▌▒▒█▒▒▐█▒▒▒▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ |/ ╚╗╔╝║║♫═╦╦╦╔╗ ▀▌▒▒▒▒▒▒▀▒▀▒▒▒▒▒▒▀▀▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ▄▄ ╔╝╚╗♫╚╣║║║║╔╣ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌▄█▒█ ╚═♫╝╚═╩═╩♫╩═╝ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒█▀ ┊  ┊  ┊  ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▀ ┊  ┊  ┊  ┊ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ ┊  ┊  ┊  ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ┊  ┊  ☆ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▌ ┊  ★ ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐ ☆ ▐▄▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▄▌ ▀▄▄▀▀▀▀▀▄▄▀▀▀▀▀▀▀▄▄▀▀▀▀▀▄▄▀ */

Compilation message (stderr)

building.cpp: In function 'void homefix()':
building.cpp:43:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         freopen("fixcode.txt", "w", stderr);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp: In function 'void home()':
building.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(namein, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
building.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(nameout, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...