結果

問題 No.325 マンハッタン距離2
ユーザー kzyKTkzyKT
提出日時 2015-04-06 03:17:17
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 554 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 144,660 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-17 06:05:14
合計ジャッジ時間 2,616 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a[4],d;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> d;
  for(int i=0; i<4; i++) {
    int k=(i/2)?-1:1;
    if(a[i]*k>0) {
      a[i+2*k]-=a[i];
      d-=a[i]*k;
      a[i]=0;
    }
  }
  if(d<=0) {
    cout << (d?0:1) << endl;
    return 0;
  }

  long long ans=0;
  for(int i=0; i<4; i++) {
    a[i]=abs(a[i]);
    ans+=(d<=a[i]);
  }
  for(int i=0; i<4; i++) {
    int x=a[i],y=a[(i+1)%4];
    ans+=max(0,d+1-max(x,d)+x-max(y,d)+y-(d<=x)-(d<=y));
  }
  cout << ans << endl;
  return 0;
}
0