Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

pizzaroot

23239번: 당근 밭 본문

공부/알고리즘

23239번: 당근 밭

pizzaroot 2022. 10. 6. 01:15

각 \(x\)좌표에 대해서 가능한 \(y\)의 개수를 더해주면 된다.

\([-L,-1]\), \(0\), \([1,h]\), \([h + 1,L]\) 4개의 구간 각각 식을 세워서 계산하면 된다.

#include <bits/stdc++.h>
#define PRECISION 0.5
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll w, h, L, ans = 0; cin >> w >> h >> L;
    for (ll i = 1; i <= L; i++) ans += (ll)sqrt(L * L - i * i + PRECISION) * 2 + 1;
    ans += L + max(0LL, L - w);
    for (ll i = 1; i <= min(L - w, h); i++) ans += (ll)sqrt((L - w) * (L - w) - i * i + PRECISION);
    for (ll i = 1; i <= min(L, h); i++) ans += (ll)sqrt(L * L - i * i + PRECISION);
    for (ll i = h + 1; i <= L; i++) {
        ll lo = -(ll)sqrt(L * L - i * i + PRECISION);
        if (L >= w + i) lo = min(lo, -(ll)sqrt((L - w - h) * (L - w - h) - (i - h) * (i - h) + PRECISION) - w);
        ll hi = (ll)sqrt((L - h) * (L - h) - (i - h) * (i - h) + PRECISION);
        if (L >= w + i) hi = max(hi, (ll)sqrt((L - w) * (L - w) - i * i + PRECISION) + w);
        ans += max(0LL, hi - lo + 1);
    }
    cout << ans << "\n";
    return 0;
}

'공부 > 알고리즘' 카테고리의 다른 글

17564번: Dishonest Driver  (0) 2022.10.06
23338번: Eatcoin  (1) 2022.10.06
17555번: Blurred Pictures  (0) 2022.10.06
17554번: City of Lights  (0) 2022.10.06
UCPC 2022 후기  (0) 2022.07.24
Comments