結果

問題 No.1874 Minimum of Sum of Rectangles
ユーザー 沙耶花沙耶花
提出日時 2022-03-11 22:53:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,016 bytes
コンパイル時間 4,386 ms
コンパイル使用メモリ 260,780 KB
実行使用メモリ 4,912 KB
最終ジャッジ日時 2023-10-14 10:34:22
合計ジャッジ時間 33,472 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 9 ms
4,348 KB
testcase_05 AC 773 ms
4,804 KB
testcase_06 AC 789 ms
4,744 KB
testcase_07 AC 792 ms
4,756 KB
testcase_08 AC 747 ms
4,680 KB
testcase_09 AC 771 ms
4,804 KB
testcase_10 AC 766 ms
4,684 KB
testcase_11 AC 765 ms
4,748 KB
testcase_12 AC 764 ms
4,604 KB
testcase_13 AC 768 ms
4,672 KB
testcase_14 AC 793 ms
4,620 KB
testcase_15 AC 776 ms
4,604 KB
testcase_16 AC 811 ms
4,608 KB
testcase_17 AC 792 ms
4,620 KB
testcase_18 AC 803 ms
4,556 KB
testcase_19 AC 788 ms
4,668 KB
testcase_20 AC 797 ms
4,912 KB
testcase_21 AC 808 ms
4,700 KB
testcase_22 AC 798 ms
4,896 KB
testcase_23 AC 800 ms
4,744 KB
testcase_24 AC 814 ms
4,752 KB
testcase_25 AC 775 ms
4,764 KB
testcase_26 AC 799 ms
4,700 KB
testcase_27 AC 793 ms
4,760 KB
testcase_28 AC 796 ms
4,560 KB
testcase_29 AC 782 ms
4,680 KB
testcase_30 AC 825 ms
4,612 KB
testcase_31 AC 799 ms
4,556 KB
testcase_32 AC 811 ms
4,760 KB
testcase_33 AC 781 ms
4,604 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 2 ms
4,352 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 771 ms
4,560 KB
testcase_38 AC 776 ms
4,684 KB
testcase_39 AC 774 ms
4,692 KB
testcase_40 AC 771 ms
4,604 KB
testcase_41 AC 771 ms
4,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000000000000000

int n;
vector<long long> x,y;

long long get2(long long mx,long long my){
	long long ret= 0;
	rep(i,n){
		ret += abs(x[i] - mx) * abs(y[i] - my);
	}
	return ret;
}

long long get(long long m){
	long long l = 0,r = 1000000;
	while(r-l>2){
		long long m0 = l + (r-l)/3;
		long long m1 = m0 + (r-l)/3;
		if(get2(m,m0)<=get2(m,m1))r = m1;
		else l = m0;
	}
	long long ret = Inf;
	for(long long i=l-2;i<=r+2;i++){
		ret = min(ret,get2(m,i));
	}
	return ret;
}

int main(){
	
	cin>>n;
	
	x.resize(n);
	y.resize(n);
	rep(i,n)cin>>x[i]>>y[i];
	
	long long l = 0,r = 1000000;
	while(r-l>2){
		long long m0 = l + (r-l)/3;
		long long m1 = m0 + (r-l)/3;
		if(get(m0)<=get(m1))r = m1;
		else l = m0;
	}
	long long ans = Inf;
	for(long long i=l-3;i<=r+3;i++)ans = min(ans,get(i));
	cout<<ans<<endl;
	
	return 0;
}
0