結果

問題 No.2438 Double Least Square
ユーザー 👑 potato167potato167
提出日時 2023-08-16 00:26:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,285 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 214,200 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 05:09:31
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 98 ms
5,376 KB
testcase_11 AC 98 ms
5,376 KB
testcase_12 AC 100 ms
5,376 KB
testcase_13 AC 97 ms
5,376 KB
testcase_14 AC 97 ms
5,376 KB
testcase_15 AC 97 ms
5,376 KB
testcase_16 AC 97 ms
5,376 KB
testcase_17 AC 101 ms
5,376 KB
testcase_18 AC 99 ms
5,376 KB
testcase_19 AC 98 ms
5,376 KB
testcase_20 AC 91 ms
5,376 KB
testcase_21 AC 88 ms
5,376 KB
testcase_22 AC 81 ms
5,376 KB
testcase_23 AC 92 ms
5,376 KB
testcase_24 AC 96 ms
5,376 KB
testcase_25 AC 81 ms
5,376 KB
testcase_26 AC 88 ms
5,376 KB
testcase_27 AC 96 ms
5,376 KB
testcase_28 AC 97 ms
5,376 KB
testcase_29 AC 95 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |                    ^

ソースコード

diff #

#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";
}
0