結果

問題 No.325 マンハッタン距離2
ユーザー sugim48sugim48
提出日時 2015-12-18 00:29:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,833 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 75,008 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 13:30:09
合計ジャッジ時間 1,793 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll solve(ll, ll, ll, ll, ll)’:
main.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int INF = INT_MAX / 2;

ll f(ll x, ll y, ll d) {
	if (x > y) swap(x, y);
	if (x < 0) return 0;
	if (d <= x) return (d + 2) * (d + 1) / 2;
	else if (d <= y) return (x + 2) * (x + 1) / 2 + (d - x) * (x + 1);
	else if (d < x + y) {
		ll _d = x + y - d - 1;
		return (x + 1) * (y + 1) - (_d + 2) * (_d + 1) / 2;
	}
	return (x + 1) * (y + 1);
}

ll g(ll x1, ll y1, ll x2, ll y2, ll d) {
	return f(x2, y2, d) - f(x2, y1 - 1, d) - f(x1 - 1, y2, d) + f(x1 - 1, y1 - 1, d);
}

ll solve(ll x1, ll y1, ll x2, ll y2, ll d) {
	if (x1 < 0 && x2 < 0) {
		x1 *= -1; x2 *= -1;
		swap(x1, x2);
	}
	if (y1 < 0 && y2 < 0) {
		y1 *= -1; y2 *= -1;
		swap(y1, y2);
	}
	if (y1 < 0) {
		swap(x1, y1);
		swap(x2, y2);
	}
	if (x1 >= 0 && y1 >= 0) return g(x1, y1, x2, y2, d);
	if (x1 < 0 && y1 >= 0) return g(0, y1, -x1, y2, d) + g(0, y1, x2, y2, d) - g(0, y1, 0, y2, d);
	if (x1 < 0 && y1 < 0) return g(0, 0, -x1, -y1, d) + g(0, 0, -x1, y2, d) + g(0, 0, x2, -y1, d) + g(0, 0, x2, y2, d) - g(0, 0, -x1, 0, d) - g(0, 0, 0, -y1, d) - g(0, 0, x2, 0, d) - g(0, 0, 0, y2, d) + 1;
}

int main() {
	ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	ll d; cin >> d;
	cout << solve(x1, y1, x2, y2, d) << endl;
}
0