結果
問題 | No.2438 Double Least Square |
ユーザー | 👑 potato167 |
提出日時 | 2023-08-16 00:26:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,285 bytes |
コンパイル時間 | 2,281 ms |
コンパイル使用メモリ | 214,252 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-26 23:08:13 |
合計ジャッジ時間 | 5,371 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:51:41: warning: 'C' may be used uninitialized [-Wmaybe-uninitialized] 51 | if(A*X[j]+B*Y[j]+C>=0) pos[j]=1; | ~~~~~~~~~~~~~^~ main.cpp:33:24: note: 'C' was declared here 33 | ll A,B,C; | ^ main.cpp:51:36: warning: 'B' may be used uninitialized [-Wmaybe-uninitialized] 51 | if(A*X[j]+B*Y[j]+C>=0) pos[j]=1; main.cpp:33:22: note: 'B' was declared here 33 | ll A,B,C; | ^ main.cpp:51:29: warning: 'A' may be used uninitialized [-Wmaybe-uninitialized] 51 | if(A*X[j]+B*Y[j]+C>=0) pos[j]=1; main.cpp:33:20: note: 'A' was declared here 33 | ll A,B,C; | ^
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(p) p.begin(),p.end() #define rep(i,a,b) for(int i=(int)a;i<(int)b;i++) const int mod=998244353; using ld = long double; int main(){ int N; cin>>N; ld ans=1e9; ll H; cin>>H; vector<ll> X(N),Y(N); vector p(N,vector(2,vector<ll>(3))); rep(i,0,N){ cin>>X[i]>>Y[i]; rep(j,0,2){ p[i][j][0]=X[i]*X[i]; p[i][j][1]=X[i]*Y[i]; p[i][j][2]=Y[i]*Y[i]; Y[i]=Y[i]-H; } Y[i]+=2*H; } vector<int> order(N); rep(i,0,N) order[i]=i; sort(all(order),[&](int l,int r){ return X[l]>X[r]; }); rep(i,0,N+2){ ll A,B,C; if(i<N) A=H-2*Y[i],B=X[i]*2,C=-H*X[i]; else if(i==N) A=1,B=0,C=0; else if(i==N+1) A=-1,B=0,C=0; vector<int> pos(N); vector<vector<ll>> q(2,vector<ll>(3)); auto f=[&](int ind,int ud,int s)->void{ rep(j,0,3) q[ud][j]+=s*p[ind][ud][j]; }; auto g=[&]()->ld{ ld tmp=0; rep(j,0,2){ tmp+=q[j][2]; if(q[j][0]) tmp-=(ld)(q[j][1]*q[j][1])/(ld)(q[j][0]); } return tmp; }; rep(j,0,N){ if(A*X[j]+B*Y[j]+C>=0) pos[j]=1; else pos[j]=0; f(j,pos[j],1); } rep(j,0,N+1){ ans=min(ans,g()); if(j==N) break; int a=order[j]; f(a,pos[a],-1); pos[a]=1-pos[a]; f(a,pos[a],1); } } cout<<fixed<<setprecision(20)<<ans<<"\n"; }