Submission #56550664


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int maxn = 4e6 + 10;
const int zero = 2e6 + 5;

long long dx[maxn], dy[maxn];

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

    int n, d;
    cin>>n>>d;

    vector<int> vx(n), vy(n);
    for(int i = 0; i < n; i++){
        cin>>vx[i]>>vy[i];
        vx[i] += zero;
        vy[i] += zero;
    }

    sort(vx.begin(), vx.end());
    sort(vy.begin(), vy.end());

    for(int i = 0; i < n; i++){
        dx[0] += vx[i];
        dy[0] += vy[i];
    }

    int add = -n;
    int j = 0;
    for(int i = 1; i < maxn; i++){
        dx[i] = dx[i-1] + add;
        while(j < n && vx[j] == i){
            add += 2;
            ++j;
        }
    }

    add = -n;
    j = 0;
    int pos = 0;
    for(int i = 1; i < maxn; i++){
        dy[i] = dy[i-1] + add;
        while(j < n && vy[j] == i){
            add += 2;
            ++j;
        }
        if(dy[i] < dy[pos]) pos = i;
    }

    long long ans = 0;
    for(int i = 0; i < maxn; i++){
        if(dx[i] + dy[pos] > d) continue;

        int rem = d - dx[i];

        {
            int lo = pos, hi = maxn;
            while(lo + 1 < hi){
                int mid = (lo + hi) / 2;
                if(dy[mid] <= rem) lo = mid;
                else hi = mid;
            }
            ans += lo - pos + 1;
        }
        {
            int lo = 0, hi = pos;
            while(lo + 1 < hi){
                int mid = (lo + hi) / 2;
                if(dy[mid] <= rem) hi = mid;
                else lo = mid;
            }
            ans += pos - hi;
        }
    }

    cout << ans << '\n';

    return 0;
}

Submission Info

Submission Time
Task E - Manhattan Multifocal Ellipse
User Peti25
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1712 Byte
Status AC
Exec Time 261 ms
Memory 67240 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.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, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 40 ms 65964 KiB
00_sample_02.txt AC 40 ms 66040 KiB
00_sample_03.txt AC 41 ms 65908 KiB
01_random_01.txt AC 91 ms 65920 KiB
01_random_02.txt AC 55 ms 65980 KiB
01_random_03.txt AC 66 ms 65972 KiB
01_random_04.txt AC 47 ms 65840 KiB
01_random_05.txt AC 49 ms 65908 KiB
01_random_06.txt AC 74 ms 67240 KiB
01_random_07.txt AC 74 ms 67192 KiB
01_random_08.txt AC 41 ms 65992 KiB
01_random_09.txt AC 41 ms 65924 KiB
01_random_10.txt AC 40 ms 65992 KiB
01_random_11.txt AC 40 ms 65932 KiB
01_random_12.txt AC 40 ms 65928 KiB
01_random_13.txt AC 41 ms 65980 KiB
01_random_14.txt AC 40 ms 65964 KiB
01_random_15.txt AC 41 ms 65976 KiB
01_random_16.txt AC 40 ms 65928 KiB
01_random_17.txt AC 40 ms 65840 KiB
01_random_18.txt AC 41 ms 65980 KiB
01_random_19.txt AC 41 ms 65928 KiB
01_random_20.txt AC 40 ms 65904 KiB
02_handmade_01.txt AC 40 ms 65992 KiB
02_handmade_02.txt AC 40 ms 65936 KiB
02_handmade_03.txt AC 261 ms 65836 KiB
02_handmade_04.txt AC 261 ms 65984 KiB
02_handmade_05.txt AC 259 ms 65968 KiB
02_handmade_06.txt AC 259 ms 65916 KiB