結果

問題 No.325 マンハッタン距離2
ユーザー piyoko_212piyoko_212
提出日時 2015-12-20 23:36:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 828 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 35,784 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 14:38:53
合計ジャッジ時間 1,051 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 0 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 0 ms
4,348 KB
testcase_08 AC 0 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 0 ms
4,348 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 0 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 0 ms
4,348 KB
testcase_19 AC 0 ms
4,348 KB
testcase_20 AC 0 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 0 ms
4,348 KB
testcase_25 AC 0 ms
4,348 KB
testcase_26 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         int a,b,c,d,e;scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
using namespace std;
int ABS(int a){return max(a,-a);}
int main(){
	int a,b,c,d,e;scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	for(int i=0;i<20;i++){
	int ab=0;
	if((long long)a*c>0)ab=min(ABS(a),ABS(c));
	int bb=0;
	if((long long)b*d>0)bb=min(ABS(b),ABS(d));
	
	a=max(a,-e+bb);
	b=max(b,-e+ab);
	c=min(c,e-bb);
	d=min(d,e-ab);
	//printf("%d %d %d %d\n",a,b,c,d);
	if(a>c||b>d){
		printf("0\n");return 0;
	}
	
	}
	long long ret=(long long)(c-a+1)*(d-b+1);
	if(ABS(a)+ABS(b)>e){
		int r=ABS(a)+ABS(b)-e;
		ret-=(long long)r*(r+1)/2;
	}
	if(ABS(a)+ABS(d)>e){
		int r=ABS(a)+ABS(d)-e;
		ret-=(long long)r*(r+1)/2;
	}
	if(ABS(c)+ABS(b)>e){
		int r=ABS(c)+ABS(b)-e;
		ret-=(long long)r*(r+1)/2;
	}
	if(ABS(c)+ABS(d)>e){
		int r=ABS(c)+ABS(d)-e;
		ret-=(long long)r*(r+1)/2;
	}
	
	printf("%lld\n",ret);
}
0