Submission #61818360


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 5;
const ll llINF = 1e18;
const int SZ = 1 << 18;
const int mxn = 2e5 + 5;
double dy[] = {0.5, 0.5, -0.5, -0.5};
double dx[] = {0.5, -0.5, 0.5, -0.5};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

const int INF = 1e9 + 5;
const ll llINF = 1e18;
const int SZ = 1 << 18;
const int mxn = 2e5 + 5;

double dy[] = {0.5, 0.5, -0.5, -0.5};
double dx[] = {0.5, -0.5, 0.5, -0.5};

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

    ll R;
    cin >> R;

    ll ans = 0;

    // 원 R이 있는 곳이 원점이고
    // R안에 들어오려면 모든 사각형의 꼭짓점이 원의 넓이 안에 존재해야한다.

    for(int i = -R; i <= R; i++) {
        // for(int j = -R; j <= R; j++) {
        //     bool ok = true;
        //     for(int k = 0; k < 4; k++) {
        //         double a = (double)i + dx[k];
        //         double b = (double)j + dy[k];
        //         if (a*a + b*b > R*R) {
        //             ok = false;
        //             break;
        //         }
        //     }
        //     if(ok) {
        //         ans++;
        //     }
        // }

        int lo = -R;
        int hi = 0;

        while(lo <= hi) {
            int mid = (lo + hi) / 2;
            bool ok = true;
            for(int k = 0; k < 4; k++) {
                double a = (double)i + dx[k];
                double b = (double)mid + dy[k];
                if (a*a + b*b > R*R) {
                    ok = false;
                    break;
                }
            }

            // 포함이 되면?
            if(ok) {
                hi = mid - 1;
            } else {
                lo = mid + 1;
            }
        }

        int lo2 = 1;
        int hi2 = R;

        while(lo2 <= hi2) {
            int mid = (lo2 + hi2) / 2;
            // 포함이 되면?
            bool ok = true;
            for(int k = 0; k < 4; k++) {
                double a = (double)i + dx[k];
                double b = (double)mid + dy[k];
                if (a*a + b*b > R*R) {
                    ok = false;
                    break;
                }
            }

            // 반대로 포함이 되면 상한을 높여야함
            if(ok) {
                lo2 = mid + 1;
            } else {
                hi2 = mid - 1;
            }
        }

        ans += (lo2 - lo);
    }

    cout << ans << endl;

    return 0;
}

Submission Info

Submission Time
Task D - Squares in Circle
User scalalang
Language C++ 20 (gcc 12.2)
Score 400
Code Size 2450 Byte
Status AC
Exec Time 349 ms
Memory 3612 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 25
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3528 KB
00_sample_01.txt AC 1 ms 3468 KB
00_sample_02.txt AC 1 ms 3608 KB
01_random_00.txt AC 85 ms 3404 KB
01_random_01.txt AC 309 ms 3472 KB
01_random_02.txt AC 144 ms 3464 KB
01_random_03.txt AC 333 ms 3396 KB
01_random_04.txt AC 216 ms 3344 KB
01_random_05.txt AC 232 ms 3404 KB
01_random_06.txt AC 316 ms 3472 KB
01_random_07.txt AC 62 ms 3340 KB
01_random_08.txt AC 234 ms 3396 KB
01_random_09.txt AC 15 ms 3464 KB
01_random_10.txt AC 341 ms 3416 KB
01_random_11.txt AC 342 ms 3468 KB
01_random_12.txt AC 343 ms 3404 KB
01_random_13.txt AC 349 ms 3472 KB
01_random_14.txt AC 341 ms 3472 KB
01_random_15.txt AC 346 ms 3612 KB
01_random_16.txt AC 341 ms 3464 KB
01_random_17.txt AC 341 ms 3468 KB
01_random_18.txt AC 341 ms 3476 KB
01_random_19.txt AC 344 ms 3468 KB
01_random_20.txt AC 1 ms 3412 KB
01_random_21.txt AC 345 ms 3436 KB


2025-03-05 (Wed)
18:08:33 +00:00