結果

問題 No.325 マンハッタン距離2
ユーザー kzyKTkzyKT
提出日時 2015-12-07 15:15:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 795 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 145,196 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 19:57:49
合計ジャッジ時間 2,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
  ll 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 << 0 << endl;
    return 0;
  }

  ll ans=1;//原点の分
  for(int i=0; i<4; i++) {
    ll x=abs(a[i]),y=abs(a[(i+1)%4]),z;
    ans-=min(d,x)+1;//重複分
    if(x>y) swap(x,y);

    //0からmin(d,x)まで
    z=min(d,x);
    ans+=(z+1)*(z+2)/2;
    if(d<=x) continue;

    //x+1からmin(d,y)まで
    z=min(d,y);
    ans+=(z-x)*(x+1);
    if(d<=y) continue;

    //y+1からmin(d,x+y)まで
    z=x+y-min(d,x+y);
    ans+=x*(x+1)/2-z*(z+1)/2;
  }
  cout << ans << endl;
  return 0;
}
0