結果
問題 | No.325 マンハッタン距離2 |
ユーザー | mayoko_ |
提出日時 | 2015-12-18 11:04:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 2,316 bytes |
コンパイル時間 | 618 ms |
コンパイル使用メモリ | 77,704 KB |
実行使用メモリ | 4,368 KB |
最終ジャッジ日時 | 2023-10-14 13:50:42 |
合計ジャッジ時間 | 1,610 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 1 ms
4,352 KB |
testcase_02 | AC | 1 ms
4,352 KB |
testcase_03 | AC | 1 ms
4,356 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 1 ms
4,352 KB |
testcase_06 | AC | 1 ms
4,356 KB |
testcase_07 | AC | 2 ms
4,352 KB |
testcase_08 | AC | 1 ms
4,352 KB |
testcase_09 | AC | 1 ms
4,352 KB |
testcase_10 | AC | 2 ms
4,352 KB |
testcase_11 | AC | 1 ms
4,348 KB |
testcase_12 | AC | 2 ms
4,352 KB |
testcase_13 | AC | 2 ms
4,348 KB |
testcase_14 | AC | 2 ms
4,368 KB |
testcase_15 | AC | 1 ms
4,348 KB |
testcase_16 | AC | 1 ms
4,352 KB |
testcase_17 | AC | 2 ms
4,352 KB |
testcase_18 | AC | 1 ms
4,352 KB |
testcase_19 | AC | 1 ms
4,352 KB |
testcase_20 | AC | 1 ms
4,352 KB |
testcase_21 | AC | 1 ms
4,352 KB |
testcase_22 | AC | 1 ms
4,352 KB |
testcase_23 | AC | 2 ms
4,352 KB |
testcase_24 | AC | 2 ms
4,352 KB |
testcase_25 | AC | 1 ms
4,352 KB |
testcase_26 | AC | 1 ms
4,352 KB |
ソースコード
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> //#include<cctype> #include<climits> #include<iostream> #include<string> #include<vector> #include<map> //#include<list> #include<queue> #include<deque> #include<algorithm> //#include<numeric> #include<utility> #include<complex> //#include<memory> #include<functional> #include<cassert> #include<set> #include<stack> const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; ull calc(ll x, ll y, ll d) { ull ret = 0; if (d <= y) { if (d <= x) { ret = (d+2)*(d+1)/2; } else { ret = (d+d-x+2)*(x+1)/2; } } else if (d-y <= x) { ret = (y+1)*(d-y+1); if (d >= x) { ret += (y + d-x+1) * (x-d+y) / 2; } else { ret += y*(y+1)/2; } } else { ret += (y+1)*(x+1); } return ret; } ull calc2(ll low, ll high, ll d) { ll mini = max(low, -d); ll maxi = min(d, high); return maxi-mini+1; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll x1, y1, x2, y2, d; cin >> x1 >> y1 >> x2 >> y2 >> d; ull ans = 0; if (y2 >= 0 && x2 >= 0) { ll dx = max<ll>(0, x1); ll dy = max<ll>(0, y1); if (d-dx-dy >= 0) ans += calc(x2-dx, y2-dy, d-dx-dy); } //cout << ans << endl; if (y2 >= 0 && x1 <= 0) { ll dx = max<ll>(0, -x2); ll dy = max<ll>(0, y1); if (d-dx-dy >= 0) ans += calc(-x1-dx, y2-dy, d-dx-dy); } //cout << ans << endl; if (y1 <= 0 && x1 <= 0) { ll dx = max<ll>(0, -x2); ll dy = max<ll>(0, -y2); if (d-dx-dy >= 0) ans += calc(-x1-dx, -y1-dy, d-dx-dy); } //cout << ans << endl; if (y1 <= 0 && x2 >= 0) { ll dx = max<ll>(0, x1); ll dy = max<ll>(0, -y2); if (d-dx-dy >= 0) ans += calc(x2-dx, -y1-dy, d-dx-dy); } //cout << ans << endl; if (x1 <= 0 && 0 <= x2) ans -= calc2(y1, y2, d); //cout << ans << endl; if (y1 <= 0 && 0 <= y2) ans -= calc2(x1, x2, d); //cout << ans << endl; if (x1 <= 0 && 0 <= x2 && y1 <= 0 && 0 <= y2) ans--; cout << ans << endl; return 0; }