結果

問題 No.325 マンハッタン距離2
ユーザー FF256grhyFF256grhy
提出日時 2015-12-18 14:21:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 810 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 25,984 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 13:57:33
合計ジャッジ時間 1,507 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,356 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,356 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,356 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 1 ms
4,356 KB
testcase_22 AC 1 ms
4,356 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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