답안 #940958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940958 2024-03-08T03:04:18 Z 8pete8 Building Bridges (CEOI17_building) C++17
100 / 100
45 ms 71352 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
//#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#define int long long 
const int mxn=5e6,inf=1e18,minf=-1e18,Mxn=2e6,lg=63;
int mod=1e9+7;
int root,n;
void setIO(string name){
	ios_base::sync_with_stdio(0); cin.tie(0);		
	freopen((name+".in").c_str(),"r",stdin);		
	freopen((name+".out").c_str(),"w",stdout);	
}	
struct line{
	int m,c;
	int get(int x){return (x*m)+c;}
};
int v1[mxn+10],v2[mxn+10],dp[mxn+10];
struct lichao{
	line v[mxn+10];
	void init(int n){for(int i=0;i<=4*n;i++)v[i]=(line){0,inf};}
	void add(int l,int r,int pos,line x){
		int mid=l+(r-l)/2;
		bool m=x.get(mid)<v[pos].get(mid);
		bool lef=x.get(l)<v[pos].get(l);
		if(m)swap(v[pos],x);
		if(l==r)return;
		if(lef!=m)add(l,mid,pos*2,x);
		else add(mid+1,r,pos*2+1,x);
	}
	int qry(int l,int r,int pos,int x){
		int mid=l+(r-l)/2;
		if(l==r)return v[pos].get(x);
		if(x<=mid)return min(qry(l,mid,pos*2,x),v[pos].get(x));
		return min(qry(mid+1,r,pos*2+1,x),v[pos].get(x));
	}
}t;
int32_t main(){
	fastio
	int n;cin>>n;
	int mx=0;
	for(int i=1;i<=n;i++)cin>>v1[i],mx=max(mx,v1[i]);
	for(int i=1;i<=n;i++)cin>>v2[i],v2[i]+=v2[i-1];
	t.init(mx);
	t.add(1,mx,1,(line){-2*v1[1],-v2[1]+(v1[1]*v1[1])});
	for(int i=2;i<=n;i++){
		dp[i]=t.qry(1,mx,1,v1[i])+(v1[i]*v1[i])+v2[i-1];
		t.add(1,mx,1,(line){-2*v1[i],dp[i]-v2[i]+(v1[i]*v1[i])});
	}
	cout<<dp[n];
}


/*


*/

Compilation message

building.cpp: In function 'void setIO(std::string)':
building.cpp:39:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
building.cpp:40:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 15000 KB Output is correct
2 Correct 32 ms 14940 KB Output is correct
3 Correct 31 ms 14940 KB Output is correct
4 Correct 30 ms 14940 KB Output is correct
5 Correct 29 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 8796 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 32 ms 15000 KB Output is correct
7 Correct 32 ms 14940 KB Output is correct
8 Correct 31 ms 14940 KB Output is correct
9 Correct 30 ms 14940 KB Output is correct
10 Correct 29 ms 21084 KB Output is correct
11 Correct 36 ms 13908 KB Output is correct
12 Correct 36 ms 13916 KB Output is correct
13 Correct 25 ms 7776 KB Output is correct
14 Correct 39 ms 16148 KB Output is correct
15 Correct 30 ms 21852 KB Output is correct
16 Correct 30 ms 22088 KB Output is correct
17 Correct 45 ms 71352 KB Output is correct
18 Correct 11 ms 7508 KB Output is correct