算法1
(暴力枚举) $O(1)$
纯找规律,做一条y=-x的直线
C++ 代码
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
long long x,y;
long long ans;
cin>>x>>y;
if(y>=-x){
ans=4*max(abs(x),abs(y))*max(abs(x),abs(y))+x-y;
}else{
if(abs(x)<abs(y)+1){
ans=(2*abs(y)+1)*(2*abs(y)+1)+y-x-1;
}else{
ans=(2*abs(x)-1)*(2*abs(x)-1)+y-x-1;
}
}
cout<<ans;
}