Submission #557626

# Submission time Handle Problem Language Result Execution time Memory
557626 2022-05-05T16:03:17 Z krit3379 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

struct A{
    int x,y;
}a[N];

int cnt1,cnt2;
long long ans;
bitset<N> vis1,vis2;
vector<int> v1,v2,temp;

int main(){
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=2*n;i++)scanf("%d %d",&a[i].x,&a[i].y);
    for(i=1;i<=2*n;i++){
        if(a[i].y<1)ans+=1-a[i].y,a[i].y=1;
        if(a[i].y>2)ans+=a[i].y-2,a[i].y=2;
        if(a[i].y==1)cnt1++,v1.push_back(a[i].x);
        else cnt2++,v2.push_back(a[i].x);
    }
    if(cnt1>cnt2)swap(cnt1,cnt2),swap(v1,v2);
    ans+=n-cnt1;
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    for(i=0;i<cnt1;i++){
        if(v1[i]>0)break;
        ans+=1-v1[i];
        v1[i]=1;
    }
    for(i=cnt1-1;i>=0;i--){
        if(v1[i]<=n)break;
        ans+=v1[i]-n;
        v1[i]=n;
    }
    for(i=0;i<cnt2;i++){
        if(v2[i]>0)break;
        ans+=1-v2[i];
        v2[i]=1;
    }
    for(i=cnt2-1;i>=0;i--){
        if(v2[i]<=n)break;
        ans+=v2[i]-n;
        v2[i]=n;
    }
    for(i=0;i<cnt1;i++){
        if(vis1[v1[i]])temp.push_back(v1[i]);
        vis1[v1[i]]=true;
    }
    for(i=0;i<cnt2;i++){
        if(vis2[v2[i]])temp.push_back(v2[i]);
        vis2[v2[i]]=true;
    }
    for(i=1,j=0;i<=n;i++){
        if(!vis1[i])ans+=abs(i-temp[j++]);
        if(!vis2[i])ans+=abs(i-temp[j++]);
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
joi2019_ho_t4.cpp:19:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     for(i=1;i<=2*n;i++)scanf("%d %d",&a[i].x,&a[i].y);
      |                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Halted 0 ms 0 KB -