結果
| 問題 | No.325 マンハッタン距離2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-07 15:50:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 510 bytes |
| 記録 | |
| コンパイル時間 | 1,649 ms |
| コンパイル使用メモリ | 159,460 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-14 18:19:48 |
| 合計ジャッジ時間 | 2,284 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#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;
}
}
ll ans=d<0?0:1;
for(int i=0;d>=0&&i<4;i++) {
ll x=abs(a[i]),y=abs(a[(i+1)%4]);
ans-=min(d,x)+1;
ll z=min(d,x+y);
x-=max(x,z);
y-=max(y,z);
ans+=max(0LL,(z+1)*(z+2)/2-(x-1)*x/2-(y-1)*y/2);
}
cout<<ans<<endl;
return 0;
}