Submission #20008449


Source Code Expand

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template <typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++;
else if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << s.substr(0, i) << " = " << x << " | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

long long sqrtt(long long x) {
    long long l = 0, r = 2e9;
    while (l < r) {
        long long m = (l + r) / 2;
        if (m * m > x)
            r = m;
        else
            l = m + 1;
    }
    return l - 1;
}

long long ceilt(long long x, long long y) {
    if (y < 0) {
        x = -x;
        y = -y;
    }
    if (x < 0)
        return x / y;
    return (x + y - 1) / y;
}

long long floort(long long x, long long y) {
    if (y < 0) {
        x = -x;
        y = -y;
    }
    if (x >= 0)
        return x / y;
    return (x - y + 1) / y;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long double x, y, r;
    cin >> x >> y >> r;
    long long xx = roundl(10000 * x), yy = roundl(10000 * y), rr = roundl(10000 * r);

    long long a = ceill(x - r), b = floorl(x + r), c = ceill(y - r), d = floorl(y + r), ret = 0;
    for (long long i=a; i<=b; i++) {
        long long sq = sqrtt(rr * rr - (10000 * i - xx) * (10000 * i - xx));
        long long e = max(ceilt(yy - sq, 10000), c), f = min(floort(yy + sq, 10000), d);
        ret += max(f - e + 1, 0LL);
    }
    cout << ret << "\n";

    return 0;
}

Submission Info

Submission Time
Task D - Circle Lattice Points
User smax
Language C++ (GCC 9.2.1)
Score 400
Code Size 2237 Byte
Status AC
Exec Time 38 ms
Memory 3836 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 46
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All extreme_00.txt, extreme_01.txt, extreme_02.txt, extreme_03.txt, handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_marginal_00.txt, handmade_marginal_01.txt, handmade_marginal_02.txt, handmade_marginal_03.txt, handmade_marginal_04.txt, handmade_marginal_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_integer_00.txt, random_integer_01.txt, random_integer_02.txt, random_integer_03.txt, random_integer_04.txt, random_integer_05.txt, random_integer_06.txt, random_integer_07.txt, random_integer_08.txt, random_integer_09.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
extreme_00.txt AC 38 ms 3716 KiB
extreme_01.txt AC 35 ms 3716 KiB
extreme_02.txt AC 28 ms 3732 KiB
extreme_03.txt AC 33 ms 3776 KiB
handmade_00.txt AC 2 ms 3720 KiB
handmade_01.txt AC 10 ms 3688 KiB
handmade_02.txt AC 3 ms 3752 KiB
handmade_marginal_00.txt AC 37 ms 3720 KiB
handmade_marginal_01.txt AC 32 ms 3720 KiB
handmade_marginal_02.txt AC 27 ms 3696 KiB
handmade_marginal_03.txt AC 34 ms 3724 KiB
handmade_marginal_04.txt AC 27 ms 3764 KiB
handmade_marginal_05.txt AC 30 ms 3716 KiB
random_00.txt AC 27 ms 3720 KiB
random_01.txt AC 9 ms 3692 KiB
random_02.txt AC 30 ms 3728 KiB
random_03.txt AC 17 ms 3720 KiB
random_04.txt AC 20 ms 3724 KiB
random_05.txt AC 9 ms 3724 KiB
random_06.txt AC 31 ms 3744 KiB
random_07.txt AC 14 ms 3776 KiB
random_08.txt AC 24 ms 3736 KiB
random_09.txt AC 35 ms 3724 KiB
random_10.txt AC 32 ms 3700 KiB
random_11.txt AC 14 ms 3836 KiB
random_12.txt AC 21 ms 3736 KiB
random_13.txt AC 28 ms 3720 KiB
random_14.txt AC 29 ms 3736 KiB
random_15.txt AC 21 ms 3704 KiB
random_16.txt AC 13 ms 3700 KiB
random_17.txt AC 28 ms 3724 KiB
random_18.txt AC 24 ms 3748 KiB
random_19.txt AC 5 ms 3724 KiB
random_integer_00.txt AC 17 ms 3704 KiB
random_integer_01.txt AC 9 ms 3716 KiB
random_integer_02.txt AC 23 ms 3776 KiB
random_integer_03.txt AC 23 ms 3696 KiB
random_integer_04.txt AC 12 ms 3700 KiB
random_integer_05.txt AC 7 ms 3740 KiB
random_integer_06.txt AC 27 ms 3724 KiB
random_integer_07.txt AC 18 ms 3692 KiB
random_integer_08.txt AC 14 ms 3724 KiB
random_integer_09.txt AC 30 ms 3736 KiB
sample_01.txt AC 2 ms 3716 KiB
sample_02.txt AC 2 ms 3744 KiB
sample_03.txt AC 27 ms 3688 KiB