結果

問題 No.131 マンハッタン距離
ユーザー TLwiegehtt
提出日時 2015-07-12 05:52:32
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 450 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 20,480 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 05:54:20
合計ジャッジ時間 935 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:16:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d %d %d", &x, &y, &d);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int max(int x, int y){
	if(x>y){	return x;	}
	return y;
}

int min(int x, int y){
	if(x<y){	return x;	}
	return y;
}

int main(void){
	int x,y,d;
	int ans;
	scanf("%d %d %d", &x, &y, &d);
	
	if( max(x,y) <= d ){
		ans = 2*max(x,y)-d-(max(x,y)-min(x,y))+1;
	}else if(min(x,y) >= d){
		ans = d+1;
	}else{
		ans = 2*max(min(x,y),d)-d-(max(min(x,y),d)-min(min(x,y),d))+1;
	}
	
	if(ans < 0){ans=0;}
	printf("%d\n", ans);
	
	return 0;
}
0