結果

問題 No.325 マンハッタン距離2
ユーザー sugim48
提出日時 2015-12-18 00:29:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,833 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 80,844 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-16 08:13:20
合計ジャッジ時間 1,717 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]
   68 | }
      | ^

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0