Submission #1282206

#TimeUsernameProblemLanguageResultExecution timeMemory
1282206quan606303Building Bridges (CEOI17_building)C++20
100 / 100
327 ms10616 KiB
/* * @Author: RMQuan * @Date: 2025-10-22 22:10:41 * @Last Modified by: RMQuan * @Last Modified time: 2025-10-22 23:13:22 */ /*idea : */ #include <bits/stdc++.h> bool M1; #define int long long #define ll long long #define INTMAX INT_MAX #define INTMIN INT_MIN #define LONGMAX LLONG_MAX #define LONGMIN LLONG_MIN #define fi first #define se second #define memfull(a,b) memset(a,b,sizeof(a)); #define endl '\n' #define TASK "TEST" #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);} using namespace std; const int MOD=1e9+7; const int maxn=1e5+7; const int inf=1e18; int h[maxn],w[maxn],pre[maxn],n,dp[maxn]; struct point { int A,B; point() { A=0; B=inf; } point(int A_t,int B_t) { A=A_t; B=B_t; } int cal(int x) { return A*x+B; } }; struct node { node *L,*R; point X; node() { X=point(); L=NULL; R=NULL; } }; struct LCT { node *root; int N; LCT(int n):N(n),root(new node()){} void upd(node *p,int l,int r,point val) { if (val.B==inf)return ; int mid=(l+r)/2; if (p->X.cal(mid)>val.cal(mid))swap(p->X,val); if (l!=r) { if (val.A>p->X.A) { if (p->L==NULL)p->L=new node(); upd(p->L,l,mid-1,val); } else{ if (p->R==NULL)p->R=new node(); upd(p->R,mid+1,r,val); } } } int get(node *p,int l,int r,int pos) { int mid=(l+r)/2; int curr=p->X.cal(pos); if (pos==mid)return curr; else if (pos<mid) { if (p->L==NULL)return curr; else return min(curr,get(p->L,l,mid-1,pos)); } else if (pos>mid) { if (p->R==NULL)return curr; else return min(curr,get(p->R,mid+1,r,pos)); } } void update(point val) { upd(root,0,N,val); } int query(int pos) { return get(root,0,N,pos); } }; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); file(); cin>>n; for (int i=1;i<=n;i++)cin>>h[i]; for (int i=1;i<=n;i++) { cin>>w[i]; pre[i]=pre[i-1]+w[i]; } LCT lct(1e9); lct.update(point(-2*h[1],dp[1]+h[1]*h[1]-pre[1])); for (int i=2;i<=n;i++) { dp[i]=lct.query(h[i])+(h[i]*h[i]+pre[i-1]); // cerr<<dp[i]<<endl; lct.update(point(-2*h[i],dp[i]+h[i]*h[i]-pre[i])); } cout<<dp[n]; bool M2; cerr<<"-------------------------------------------------"<<endl; cerr<<"Time : "<<clock()<<" ms"<<endl; cerr<<"Memory : "<<abs(&M2-&M1)/1024/1024<<" MB"<<endl; cerr<<"-------------------------------------------------"<<endl; return 0; }

Compilation message (stderr)

building.cpp: In function 'int32_t main()':
building.cpp:25:50: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
building.cpp:113:5: note: in expansion of macro 'file'
  113 |     file();
      |     ^~~~
building.cpp:25:81: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
building.cpp:113:5: note: in expansion of macro 'file'
  113 |     file();
      |     ^~~~
building.cpp: In member function 'long long int LCT::get(node*, long long int, long long int, long long int)':
building.cpp:98:5: warning: control reaches end of non-void function [-Wreturn-type]
   98 |     }
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...