結果

問題 No.960 マンハッタン距離3
ユーザー chocoruskchocorusk
提出日時 2019-12-23 01:54:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 3,288 bytes
コンパイル時間 1,316 ms
コンパイル使用メモリ 120,184 KB
実行使用メモリ 6,612 KB
最終ジャッジ日時 2023-10-13 01:46:38
合計ジャッジ時間 12,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
5,692 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
5,380 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
5,452 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,356 KB
testcase_13 AC 2 ms
5,516 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
5,380 KB
testcase_16 AC 2 ms
5,404 KB
testcase_17 AC 2 ms
4,356 KB
testcase_18 AC 2 ms
5,400 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,356 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
5,468 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 2 ms
5,572 KB
testcase_33 AC 1 ms
4,348 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 2 ms
5,464 KB
testcase_36 AC 1 ms
4,356 KB
testcase_37 AC 3 ms
5,400 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 2 ms
5,468 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1 ms
4,348 KB
testcase_43 AC 2 ms
4,352 KB
testcase_44 AC 2 ms
5,468 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 2 ms
4,352 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 2 ms
5,580 KB
testcase_49 AC 2 ms
5,476 KB
testcase_50 AC 2 ms
5,384 KB
testcase_51 AC 2 ms
4,352 KB
testcase_52 AC 2 ms
4,352 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 1 ms
4,352 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 3 ms
5,472 KB
testcase_57 AC 1 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,352 KB
testcase_60 AC 2 ms
5,408 KB
testcase_61 AC 2 ms
4,352 KB
testcase_62 AC 2 ms
4,348 KB
testcase_63 AC 2 ms
4,348 KB
testcase_64 AC 2 ms
4,352 KB
testcase_65 AC 2 ms
4,348 KB
testcase_66 AC 2 ms
4,352 KB
testcase_67 AC 2 ms
4,352 KB
testcase_68 AC 2 ms
5,380 KB
testcase_69 AC 1 ms
4,348 KB
testcase_70 AC 2 ms
5,640 KB
testcase_71 AC 2 ms
5,576 KB
testcase_72 AC 2 ms
4,348 KB
testcase_73 AC 2 ms
5,464 KB
testcase_74 AC 2 ms
4,348 KB
testcase_75 AC 2 ms
4,352 KB
testcase_76 AC 2 ms
4,352 KB
testcase_77 AC 2 ms
4,352 KB
testcase_78 AC 1 ms
4,348 KB
testcase_79 AC 1 ms
4,352 KB
testcase_80 AC 2 ms
4,352 KB
testcase_81 AC 1 ms
4,348 KB
testcase_82 AC 2 ms
5,580 KB
testcase_83 AC 2 ms
4,348 KB
testcase_84 AC 1 ms
4,352 KB
testcase_85 AC 3 ms
5,464 KB
testcase_86 AC 1 ms
4,348 KB
testcase_87 AC 1 ms
4,348 KB
testcase_88 AC 3 ms
5,536 KB
testcase_89 AC 1 ms
4,352 KB
testcase_90 AC 2 ms
4,352 KB
testcase_91 AC 2 ms
5,420 KB
testcase_92 AC 2 ms
5,480 KB
testcase_93 AC 2 ms
4,352 KB
testcase_94 AC 2 ms
5,392 KB
testcase_95 AC 2 ms
4,356 KB
testcase_96 AC 2 ms
5,580 KB
testcase_97 AC 2 ms
4,348 KB
testcase_98 AC 2 ms
5,444 KB
testcase_99 AC 2 ms
5,520 KB
testcase_100 AC 2 ms
4,356 KB
testcase_101 AC 2 ms
4,352 KB
testcase_102 AC 2 ms
4,352 KB
testcase_103 AC 2 ms
5,384 KB
testcase_104 AC 2 ms
5,408 KB
testcase_105 AC 2 ms
5,444 KB
testcase_106 AC 2 ms
4,348 KB
testcase_107 AC 2 ms
4,352 KB
testcase_108 AC 2 ms
4,352 KB
testcase_109 AC 1 ms
4,352 KB
testcase_110 AC 2 ms
4,352 KB
testcase_111 AC 2 ms
5,388 KB
testcase_112 AC 2 ms
4,352 KB
testcase_113 AC 2 ms
5,576 KB
testcase_114 AC 2 ms
4,348 KB
testcase_115 AC 1 ms
4,348 KB
testcase_116 AC 2 ms
4,352 KB
testcase_117 AC 2 ms
4,352 KB
testcase_118 AC 2 ms
4,352 KB
testcase_119 AC 2 ms
4,352 KB
testcase_120 AC 2 ms
4,352 KB
testcase_121 AC 2 ms
4,352 KB
testcase_122 AC 2 ms
5,404 KB
testcase_123 AC 2 ms
5,440 KB
testcase_124 AC 2 ms
5,468 KB
testcase_125 AC 1 ms
4,352 KB
testcase_126 AC 1 ms
4,348 KB
testcase_127 AC 2 ms
4,348 KB
testcase_128 AC 28 ms
4,352 KB
testcase_129 AC 73 ms
5,652 KB
testcase_130 AC 51 ms
6,004 KB
testcase_131 AC 90 ms
6,396 KB
testcase_132 AC 73 ms
6,112 KB
testcase_133 AC 3 ms
4,348 KB
testcase_134 AC 22 ms
5,584 KB
testcase_135 AC 26 ms
4,380 KB
testcase_136 AC 26 ms
4,540 KB
testcase_137 AC 42 ms
5,916 KB
testcase_138 AC 54 ms
5,568 KB
testcase_139 AC 63 ms
5,568 KB
testcase_140 AC 84 ms
6,596 KB
testcase_141 AC 83 ms
6,236 KB
testcase_142 AC 35 ms
5,828 KB
testcase_143 AC 53 ms
5,196 KB
testcase_144 AC 69 ms
5,968 KB
testcase_145 AC 7 ms
5,484 KB
testcase_146 AC 17 ms
4,352 KB
testcase_147 AC 58 ms
6,368 KB
testcase_148 AC 37 ms
4,504 KB
testcase_149 AC 48 ms
5,340 KB
testcase_150 AC 68 ms
5,948 KB
testcase_151 AC 5 ms
5,508 KB
testcase_152 AC 59 ms
5,696 KB
testcase_153 AC 88 ms
6,464 KB
testcase_154 AC 4 ms
4,356 KB
testcase_155 AC 61 ms
5,844 KB
testcase_156 AC 22 ms
5,644 KB
testcase_157 AC 59 ms
6,200 KB
testcase_158 AC 81 ms
6,612 KB
testcase_159 AC 12 ms
4,352 KB
testcase_160 AC 5 ms
4,348 KB
testcase_161 AC 71 ms
5,952 KB
testcase_162 AC 76 ms
6,352 KB
testcase_163 AC 43 ms
5,956 KB
testcase_164 AC 81 ms
6,248 KB
testcase_165 AC 64 ms
5,920 KB
testcase_166 AC 12 ms
4,352 KB
testcase_167 AC 40 ms
5,116 KB
testcase_168 AC 27 ms
5,796 KB
testcase_169 AC 30 ms
4,468 KB
testcase_170 AC 24 ms
4,352 KB
testcase_171 AC 42 ms
4,928 KB
testcase_172 AC 31 ms
4,496 KB
testcase_173 AC 8 ms
4,348 KB
testcase_174 AC 71 ms
5,908 KB
testcase_175 AC 87 ms
6,540 KB
testcase_176 AC 59 ms
5,440 KB
testcase_177 AC 9 ms
5,752 KB
testcase_178 AC 61 ms
5,844 KB
testcase_179 AC 66 ms
5,768 KB
testcase_180 AC 82 ms
6,236 KB
testcase_181 AC 18 ms
4,352 KB
testcase_182 AC 36 ms
5,968 KB
testcase_183 AC 50 ms
6,100 KB
testcase_184 AC 38 ms
4,952 KB
testcase_185 AC 60 ms
5,568 KB
testcase_186 AC 74 ms
6,348 KB
testcase_187 AC 55 ms
5,320 KB
testcase_188 AC 2 ms
4,352 KB
testcase_189 AC 2 ms
4,352 KB
testcase_190 AC 2 ms
4,352 KB
testcase_191 AC 2 ms
4,352 KB
testcase_192 AC 2 ms
4,348 KB
testcase_193 AC 2 ms
4,348 KB
testcase_194 AC 2 ms
4,348 KB
testcase_195 AC 2 ms
5,516 KB
testcase_196 AC 53 ms
5,544 KB
testcase_197 AC 16 ms
5,660 KB
testcase_198 AC 40 ms
4,836 KB
testcase_199 AC 59 ms
6,048 KB
testcase_200 AC 69 ms
6,104 KB
testcase_201 AC 40 ms
5,864 KB
testcase_202 AC 63 ms
5,800 KB
testcase_203 AC 34 ms
5,664 KB
testcase_204 AC 82 ms
6,320 KB
testcase_205 AC 39 ms
4,784 KB
testcase_206 AC 77 ms
6,440 KB
testcase_207 AC 57 ms
6,120 KB
testcase_208 AC 60 ms
5,520 KB
testcase_209 AC 19 ms
5,548 KB
testcase_210 AC 9 ms
4,348 KB
testcase_211 AC 28 ms
5,788 KB
testcase_212 AC 19 ms
4,352 KB
testcase_213 AC 40 ms
5,092 KB
testcase_214 AC 84 ms
6,576 KB
testcase_215 AC 68 ms
6,088 KB
testcase_216 AC 81 ms
6,276 KB
testcase_217 AC 45 ms
4,908 KB
testcase_218 AC 82 ms
6,452 KB
testcase_219 AC 42 ms
5,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
		ll ans=x[0]*y[0]+(w-x[n-1]+1)*(h-y[n-1]+1);
		if(n==2) ans+=x[n-1]-x[0]-1;
		cout<<ans<<endl;
		return 0;
	}
	if(y1[0]==y1[n-1]){
		sort(x, x+n);
		sort(y, y+n);
		ll ans=(w-x[n-1]+1)*y[0]+x[0]*(h-y[n-1]+1);
		if(n==2) ans+=x[n-1]-x[0]-1;
		cout<<ans<<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});
				}
			}
		}
	}
	if(st.empty()){
		cout<<0<<endl;
		return 0;
	}
	const ll INF=1e18;
	ll ans=0;
	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) ans+=max(0ll, h-y0);
		}else if(!dame2){
			if(1<=x0 && x0<=w) ans+=max(0ll, y0-1);
		}
		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) ans+=max(0ll, w-x0);
		}else if(!dame2){
			if(1<=y0 && y0<=h) ans+=max(0ll, x0-1);
		}
		if(1<=x0 && x0<=w && 1<=y0 && y0<=h) ans++;
	}
	if(st.size()==1){
		cout<<ans<<endl;
		return 0;
	}
	assert(st.size()==2);
	ll ax[2], ay[2];
	int c=0;
	for(auto p:st){
		ax[c]=p.first, ay[c]=p.second;
		c++;
	}
	if(ay[0]<ay[1]){
		ll mn=max({0ll, 1-ax[0], 1-ay[0]}), mx=min({ax[1]-ax[0], w-ax[0], h-ay[0]});
		ans+=max(0ll, mx-mn-1);
	}else{
		ll mn=max({0ll, 1-ax[0], ay[0]-h}), mx=min({ax[1]-ax[0], w-ax[0], ay[0]-1});
		ans+=max(0ll, mx-mn-1);
	}
	cout<<ans<<endl;
	return 0;
}
0