結果
問題 | No.960 マンハッタン距離3 |
ユーザー |
![]() |
提出日時 | 2019-12-23 01:02:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,917 bytes |
コンパイル時間 | 1,359 ms |
コンパイル使用メモリ | 122,900 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-14 21:55:09 |
合計ジャッジ時間 | 10,999 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 143 WA * 73 |
ソースコード
#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 dame1=0, dame2=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)){ dame1=1; break; } } y0-=2*INF; for(int k=0; k<n; k++){ if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){ dame2=1; break; } } y0+=INF; if(!dame1 && !dame2){ if(1<=x0 && x0<=w) cout<<h<<endl; else cout<<0<<endl; return 0; }else if(!dame1){ if(1<=x0 && x0<=w) cout<<max(0ll, h-y0+1)<<endl; else cout<<0<<endl; }else if(!dame2){ if(1<=x0 && x0<=w) cout<<max(0ll, y0)<<endl; else cout<<0<<endl; } x0+=INF; dame1=0, dame2=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)){ dame1=1; break; } } x0-=2*INF; for(int k=0; k<n; k++){ if(abs(x[k]-x0)+abs(y[k]-y0)!=abs(x[0]-x0)+abs(y[0]-y0)){ dame2=1; break; } } x0+=INF; if(!dame1 && !dame2){ if(1<=y0 && y0<=h) cout<<w<<endl; else cout<<0<<endl; return 0; }else if(!dame1){ if(1<=y0 && y0<=h) cout<<max(0ll, w-x0+1)<<endl; else cout<<0<<endl; }else if(!dame2){ if(1<=y0 && y0<=h) cout<<max(0ll, x0)<<endl; else cout<<0<<endl; } } 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; }