結果

問題 No.325 マンハッタン距離2
コンテスト
ユーザー FF256grhy
提出日時 2015-12-18 14:21:57
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 810 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 40,192 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-05 13:39:42
合計ジャッジ時間 1,084 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

long long int max(long long int a, long long int b) {
	return (a > b ? a : b);
}

long long int sum(long long int n) {
	return n * (n + 1) / 2;
}

long long int f(long long int a, long long int b, long long int l) {
	if(l <= 0 || a <= 0 || b <= 0) { return 0; }
	if(l < a + b) { return sum(l) - sum( max(0, l - a) ) - sum( max(0, l - b) ); }
	return a * b;
}

int main(void) {
	long long int x1, y1, x2, y2, d;
	scanf("%lld%lld%lld%lld%lld", &x1, &y1, &x2, &y2, &d);
	
	long long int ans = 0, i, a, b, temp;
	for(i = 0; i < 4; i++) {
		a = max(x1, 0), b = max(y1, 1);
		ans += f(x2 - a + 1, y2 - b + 1, d - (a + b - 1));
		
		temp = x1;
		x1 = -y2;
		y2 =  x2;
		x2 = -y1;
		y1 =  temp;
	}
	
	if(x1 <= 0 && 0 <= x2 && y1 <= 0 && 0 <= y2) { ans++; }
	
	printf("%lld\n", ans);
	
	return 0;
}
0