結果
| 問題 |
No.960 マンハッタン距離3
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2019-12-23 00:51:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,764 bytes |
| コンパイル時間 | 1,333 ms |
| コンパイル使用メモリ | 120,888 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-14 21:41:14 |
| 合計ジャッジ時間 | 11,013 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 154 WA * 62 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
ll w, h;
cin>>w>>h;
int n;
cin>>n;
ll x[100010], y[100010];
ll x1[100010], y1[100010];
for(int i=0; i<n; i++){
cin>>x[i]>>y[i];
x1[i]=x[i]+y[i], y1[i]=x[i]-y[i];
}
sort(x1, x1+n);
sort(y1, y1+n);
ll d=max(x1[n-1]-x1[0], y1[n-1]-y1[0]);
set<P> st;
ll px[2], py[2];
if(d%2!=0){
cout<<0<<endl;
return 0;
}
if(x1[0]==x1[n-1]){
sort(x, x+n);
sort(y, y+n);
cout<<x[0]*y[0]+(w-x[n-1]+1)*(h-y[n-1]+1)<<endl;
return 0;
}
if(y1[0]==y1[n-1]){
sort(x, x+n);
sort(y, y+n);
cout<<(w-x[n-1]+1)*y[0]+x[0]*(h-y[n-1]+1)<<endl;
return 0;
}
{
px[0]=x1[n-1]-d/2, px[1]=x1[0]+d/2;
py[0]=y1[n-1]-d/2, py[1]=y1[0]+d/2;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++){
ll x0=(px[i]+py[j])/2, y0=(px[i]-py[j])/2;
if(x0*2!=px[i]+py[j]) continue;
bool dame=0;
for(int k=0; k<n; k++){
if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){
dame=1;
break;
}
}
if(!dame){
st.insert({x0, y0});
}
}
}
}
const ll INF=1e18;
for(auto p:st){
ll x0=p.first, y0=p.second;
y0+=INF;
bool dame=0;
for(int k=0; k<n; k++){
if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){
dame=1;
break;
}
}
if(!dame){
if(1<=x0 && x0<=w) cout<<max(0ll, h-(y0-INF)+1)<<endl;
else cout<<0<<endl;
return 0;
}
y0-=2*INF;
dame=0;
for(int k=0; k<n; k++){
if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){
dame=1;
break;
}
}
if(!dame){
if(1<=x0 && x0<=w) cout<<max(0ll, (y0+INF))<<endl;
else cout<<0<<endl;
return 0;
}
y0+=INF;
x0+=INF;
dame=0;
for(int k=0; k<n; k++){
if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){
dame=1;
break;
}
}
if(!dame){
if(1<=y0 && y0<=h) cout<<max(0ll, w-(x0-INF)+1)<<endl;
else cout<<0<<endl;
return 0;
}
x0-=2*INF;
dame=0;
for(int k=0; k<n; k++){
if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){
dame=1;
break;
}
}
if(!dame){
if(1<=y0 && y0<=h) cout<<max(0ll, (x0+INF))<<endl;
else cout<<0<<endl;
return 0;
}
}
int ans=0;
for(auto p:st){
if(1<=p.first && p.first<=w && 1<=p.second && p.second<=h){
ans++;
}
}
cout<<ans<<endl;
return 0;
}
chocorusk