Submission #71334665


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define M 400005
map<int,int>mp;
int tot;
int get(int x){
    if(mp.find(x)==mp.end())return mp[x]=++tot;
    return mp[x];
}
int fa[M<<1],cnt_v[M<<1],cnt_e[M<<1];
int getfa(int x){
    if(fa[x]==x)return x;
    return fa[x]=getfa(fa[x]);
}
int me(int a,int b){
    int x=getfa(a),y=getfa(b);
    if(x==y)return x;
    fa[x]=y;
    cnt_e[y]+=cnt_e[x];
    cnt_v[y]+=cnt_v[x];
    return y;
}
int main(){
    int n;
    cin >> n;
    for(int i=1;i<M;i++){
        fa[i]=i;
        cnt_v[i]=1;
    }
    for(int i=1;i<=n;i++){
        int x,r;
        scanf("%d %d",&x,&r);
        int f=me(get(x-r),get(x+r));
        cnt_e[f]++;
    }
    long long ans=0;
    for(int i=1;i<=tot;i++){
        if(getfa(i)!=i)continue;
        ans+=min(cnt_v[i],cnt_e[i]);
    }
    printf("%d\n",ans);
    return 0;
}

Submission Info

Submission Time
Task E - Distribute Bunnies
User Hacker_
Language C++23 (GCC 15.2.0)
Score 500
Code Size 887 Byte
Status AC
Exec Time 340 ms
Memory 27284 KiB

Compile Error

./Main.cpp: In function 'int main()':
./Main.cpp:41:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   41 |     printf("%d\n",ans);
      |             ~^    ~~~
      |              |    |
      |              int  long long int
      |             %lld

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 42
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, 02_small_cc_00.txt, 02_small_cc_01.txt, 02_small_cc_02.txt, 02_small_cc_03.txt, 02_small_cc_04.txt, 02_small_cc_05.txt, 02_small_cc_06.txt, 02_small_cc_07.txt, 02_small_cc_08.txt, 02_small_cc_09.txt, 02_small_cc_10.txt, 02_small_cc_11.txt, 02_small_cc_12.txt, 02_small_cc_13.txt, 02_small_cc_14.txt, 02_small_cc_15.txt, 02_small_cc_16.txt, 02_small_cc_17.txt, 02_small_cc_18.txt, 02_small_cc_19.txt, 03_path_00.txt, 03_path_01.txt, 04_cycle_00.txt, 04_cycle_01.txt, 05_namori_00.txt, 05_namori_01.txt, 05_namori_02.txt, 05_namori_03.txt, 05_namori_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 6932 KiB
00_sample_01.txt AC 3 ms 7096 KiB
00_sample_02.txt AC 3 ms 7024 KiB
01_random_00.txt AC 212 ms 21884 KiB
01_random_01.txt AC 289 ms 17852 KiB
01_random_02.txt AC 246 ms 23136 KiB
01_random_03.txt AC 339 ms 26952 KiB
01_random_04.txt AC 210 ms 21500 KiB
01_random_05.txt AC 338 ms 26624 KiB
01_random_06.txt AC 140 ms 17872 KiB
01_random_07.txt AC 340 ms 25364 KiB
01_random_08.txt AC 145 ms 18484 KiB
01_random_09.txt AC 249 ms 15284 KiB
02_small_cc_00.txt AC 131 ms 27284 KiB
02_small_cc_01.txt AC 76 ms 26440 KiB
02_small_cc_02.txt AC 78 ms 25668 KiB
02_small_cc_03.txt AC 92 ms 25168 KiB
02_small_cc_04.txt AC 79 ms 24528 KiB
02_small_cc_05.txt AC 81 ms 24160 KiB
02_small_cc_06.txt AC 82 ms 23536 KiB
02_small_cc_07.txt AC 81 ms 23100 KiB
02_small_cc_08.txt AC 82 ms 22672 KiB
02_small_cc_09.txt AC 82 ms 22084 KiB
02_small_cc_10.txt AC 82 ms 21620 KiB
02_small_cc_11.txt AC 82 ms 21400 KiB
02_small_cc_12.txt AC 82 ms 21052 KiB
02_small_cc_13.txt AC 83 ms 20448 KiB
02_small_cc_14.txt AC 82 ms 20280 KiB
02_small_cc_15.txt AC 83 ms 19732 KiB
02_small_cc_16.txt AC 83 ms 19764 KiB
02_small_cc_17.txt AC 82 ms 19196 KiB
02_small_cc_18.txt AC 82 ms 19000 KiB
02_small_cc_19.txt AC 82 ms 18740 KiB
03_path_00.txt AC 104 ms 19216 KiB
03_path_01.txt AC 184 ms 18048 KiB
04_cycle_00.txt AC 104 ms 19068 KiB
04_cycle_01.txt AC 182 ms 18232 KiB
05_namori_00.txt AC 280 ms 17168 KiB
05_namori_01.txt AC 285 ms 16992 KiB
05_namori_02.txt AC 282 ms 17012 KiB
05_namori_03.txt AC 272 ms 17044 KiB
05_namori_04.txt AC 286 ms 17168 KiB