結果
| 問題 | No.3292 World Map Distance | 
| コンテスト | |
| ユーザー |  kmjp | 
| 提出日時 | 2025-10-10 00:14:20 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 304 ms / 3,000 ms | 
| コード長 | 1,711 bytes | 
| コンパイル時間 | 2,148 ms | 
| コンパイル使用メモリ | 204,868 KB | 
| 実行使用メモリ | 23,616 KB | 
| 最終ジャッジ日時 | 2025-10-10 00:14:30 | 
| 合計ジャッジ時間 | 8,427 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 34 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N;
ll X,Y;
vector<ll> Xs,Ys;
ll hoge(vector<ll> P,ll L) {
	int i;
	vector<ll> cand;
	vector<ll> S={0};
	sort(ALL(P));
	FOR(i,N) {
		cand.push_back(P[i]-L/2);
		cand.push_back(P[i]+L/2);
		P.push_back(P[i]+L);
	}
	FOR(i,2*N) S.push_back(S.back()+P[i]);
	ll ret=-1;
	FORR(c,cand) {
		if(c-L/2<=0) c+=L;
		if(c+L/2>=2*L) c-=L;
		ll PL,PR;
		if(L%2) {
			PL=c-L/2;
			PR=c+L/2;
		}
		else {
			PL=c-L/2;
			PR=c+L/2-1;
		}
		ll sum=0;
		{
			int a=lower_bound(ALL(P),PL)-P.begin();
			int b=lower_bound(ALL(P),c)-P.begin();
			sum+=c*(b-a)-(S[b]-S[a]);
		}
		{
			int a=lower_bound(ALL(P),c+1)-P.begin();
			int b=lower_bound(ALL(P),PR+1)-P.begin();
			sum+=(S[b]-S[a])-c*(b-a);
		}
		ret=max(ret,sum);
	}
	return ret;
		
}
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X>>Y;
	FOR(i,N) {
		cin>>x>>y;
		Xs.push_back(x-1);
		Ys.push_back(y-1);
	}
	ll ret=hoge(Xs,X)+hoge(Ys,Y);
	cout<<ret<<endl;
}
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
            
            
            
        