結果

問題 No.325 マンハッタン距離2
ユーザー mayoko_
提出日時 2015-12-18 11:04:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,316 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 84,280 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-16 08:30:47
合計ジャッジ時間 1,468 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
ull calc(ll x, ll y, ll d) {
ull ret = 0;
if (d <= y) {
if (d <= x) {
ret = (d+2)*(d+1)/2;
} else {
ret = (d+d-x+2)*(x+1)/2;
}
} else if (d-y <= x) {
ret = (y+1)*(d-y+1);
if (d >= x) {
ret += (y + d-x+1) * (x-d+y) / 2;
} else {
ret += y*(y+1)/2;
}
} else {
ret += (y+1)*(x+1);
}
return ret;
}
ull calc2(ll low, ll high, ll d) {
ll mini = max(low, -d);
ll maxi = min(d, high);
return maxi-mini+1;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll x1, y1, x2, y2, d;
cin >> x1 >> y1 >> x2 >> y2 >> d;
ull ans = 0;
if (y2 >= 0 && x2 >= 0) {
ll dx = max<ll>(0, x1);
ll dy = max<ll>(0, y1);
if (d-dx-dy >= 0) ans += calc(x2-dx, y2-dy, d-dx-dy);
}
//cout << ans << endl;
if (y2 >= 0 && x1 <= 0) {
ll dx = max<ll>(0, -x2);
ll dy = max<ll>(0, y1);
if (d-dx-dy >= 0) ans += calc(-x1-dx, y2-dy, d-dx-dy);
}
//cout << ans << endl;
if (y1 <= 0 && x1 <= 0) {
ll dx = max<ll>(0, -x2);
ll dy = max<ll>(0, -y2);
if (d-dx-dy >= 0) ans += calc(-x1-dx, -y1-dy, d-dx-dy);
}
//cout << ans << endl;
if (y1 <= 0 && x2 >= 0) {
ll dx = max<ll>(0, x1);
ll dy = max<ll>(0, -y2);
if (d-dx-dy >= 0) ans += calc(x2-dx, -y1-dy, d-dx-dy);
}
//cout << ans << endl;
if (x1 <= 0 && 0 <= x2) ans -= calc2(y1, y2, d);
//cout << ans << endl;
if (y1 <= 0 && 0 <= y2) ans -= calc2(x1, x2, d);
//cout << ans << endl;
if (x1 <= 0 && 0 <= x2 && y1 <= 0 && 0 <= y2) ans--;
cout << ans << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0