2008年 日本情報オリンピック春合宿OJから、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
「競技プログラミング」を略して、「競プロ」などと呼ばれています。
#cheating - カンニング対策 (Cheating)
https://www.ioi-jp.org/camp/2008/2008-sp-tasks/2008-sp_tr-day2_21.pdf
僕が作成、提出したコードは、以下のとおりです。
/* AtCoder Problems in C++ #cheating - カンニング対策 (Cheating) https://www.ioi-jp.org/camp/2008/2008-sp-tasks/2008-sp_tr-day2_21.pdf 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; int x[200000],y[200000]; int main(void){ int n,m; cin>>n>>m; for(int i=0;i<m;i++){ cin>>x[i]>>y[i]; } sort(x,x+m); sort(y,y+m); int ok=1e9; int ng=-1; while(ok-ng>1){ int d=(ok+ng)/2; int c=0; int i=0; while(i<m){ int X=x[i]; while(i<m && x[i]<=X+d){ i++; } c++; } int j=0; while(j<m){ int Y=y[j]; while(j<m && y[j]<=Y+d){ j++; } c++; } if(c<=n){ ok=d; }else{ ng=d; } } cout<<ok<<endl; return 0; }