답안 #456276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
456276 2021-08-06T10:21:25 Z MOUF_MAHMALAT ČVENK (COI15_cvenk) C++14
38 / 100
3000 ms 84688 KB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
using namespace std;
typedef long long ll;
ll n,a[100009],b[100009],sum=1e18;
map<pair<ll,ll>,bool>mp;
ll best(ll x,ll y,ll xx,ll yy)
{
    ll ans=0,o;
    for(ll i=(1<<30); i; i>>=1)
    {
        if((i&x)==(i&xx)&&(i&y)==(i&yy))
            continue;
        if((i&x)&&(i&xx)==0)
        {
            o=0;
            for(ll j=i; j; j>>=1)
            {
                o|=(j&x);
                if((j&y))
                {
                    ans+=j;
                    y^=j;
                }
            }
            ans+=o-i+1;
            x^=i,x|=(i-1);
        }
        if((i&x)==0&&(i&xx))
        {
            o=0;
            for(ll j=i; j; j>>=1)
            {
                o|=(j&xx);
                if((j&yy))
                {
                    ans+=j;
                    yy^=j;
                }
            }
            ans+=o-i+1;
            xx^=i,xx|=(i-1);
        }
        if((i&y)&&(i&yy)==0)
        {
            o=0;
            for(ll j=i; j; j>>=1)
            {
                o|=(j&y);
                if((j&x))
                {
                    ans+=j;
                    x^=j;
                }
            }
            ans+=o-i+1;
            y^=i,y|=(i-1);
        }
        if((i&y)==0&&(i&yy))
        {
            o=0;
            for(ll j=i; j; j>>=1)
            {
                o|=(j&yy);
                if((j&xx))
                {
                    ans+=j;
                    xx^=j;
                }
            }
            ans+=o-i+1;
            yy^=i,yy|=(i-1);
        }
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    mp[{0,0}]=1;
    for(ll i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        ll x=0,y=0;
        for(ll j=(1<<30);j;j>>=1)
        {
            if(a[i]&j)
                x+=j;
            else if(b[i]&j)
                y+=j;
            mp[{x,y}]=1;
        }
    }
    for(auto z:mp)
    {
        if(z.second==0)
            continue;
        ll xo=z.first.first;
        ll yo=z.first.second;
        ll op=0;
        for(ll i=0;i<n;i++)
            op+=best(xo,yo,a[i],b[i]);
        sum=min(sum,op);
    }
    cout<<sum;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 404 KB Output is correct
2 Correct 54 ms 372 KB Output is correct
3 Correct 66 ms 376 KB Output is correct
4 Correct 106 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3052 ms 2912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3062 ms 84688 KB Time limit exceeded
2 Halted 0 ms 0 KB -