Submission #846097

# Submission time Handle Problem Language Result Execution time Memory
846097 2023-09-07T09:49:09 Z jamkel19 Cheerleaders (info1cup20_cheerleaders) C++14
100 / 100
505 ms 5892 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
typedef long long ll;
ll n;
ll k;

void liczenie(vector<ll>a,ll q,vector<ll>&x,vector<ll>&y)
{
    if(q==-1)
    {
        return;
    }
    ll jeden=0, zero=0,ifnie=0,iftak=0;
    vector<ll>b;
    vector<ll>c;
    for(ll i=0;i<a.size();i++)
    {
        if(a[i]&(1<<q))
        {
            jeden++;
            iftak+=zero;
            b.push_back(a[i]);
        }
        else
        {
            zero++;
            ifnie+=jeden;
            c.push_back(a[i]);
        }
    }
    x[q]+=ifnie;
    y[q]+=iftak;
    liczenie(b,q-1,x,y);liczenie(c,q-1,x,y);
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>k;
    n=pow(2,k);
    if(k==0)
    {
        cout<<0<<endl;
        cout<<"2222"<<endl;
        return 0;
    }
    vector<ll>a(n);
    for(ll i=0;i<n;i++)
    {
        ll w;
        cin>>w;
        a[w]=i;
    }
    ll wynik=9999999999999;
    ll wy=0;
    ll wynik2;
    for(ll i=0;i<k;i++)
    {   
        vector<ll>x(k);
        vector<ll>y(k);
        liczenie(a,k-1,x,y);
        ll r=0,u=0;
        for(ll j=0;j<k;j++)
        {
            if(x[j]>y[j])
            {
                r+=(1<<j);
            }
            u+=min(x[j],y[j]);
        }
        if(u<wynik)
        {
            wynik2=i;
            wy=r;
            wynik=u;
        }
        for(ll j=0;j<n;j++)
        {
            ll e=a[j]%2;
            a[j]/=2;
            a[j]+=(e<<(k-1));
        }
    }
    cout<<wynik<<endl;
    //cout<<wy<<endl;
    for(ll i=0;i<wynik2;i++)
    {
        cout<<2;
    }
    if((1<<(k-1)) & (wy))
    {
        cout<<1;
    }
    cout<<2;
    for(ll i=0;i<k-1;i++)
    {
        if(wy&(1<<i))
        {
            cout<<1;
        }
        cout<<2;
    }
    cout<<endl;
}

Compilation message

cheerleaders.cpp: In function 'void liczenie(std::vector<long long int>, ll, std::vector<long long int>&, std::vector<long long int>&)':
cheerleaders.cpp:18:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(ll i=0;i<a.size();i++)
      |                ~^~~~~~~~~
cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:87:17: warning: 'wynik2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |     for(ll i=0;i<wynik2;i++)
      |                ~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Correct!
2 Correct 0 ms 348 KB Correct!
3 Correct 0 ms 348 KB Correct!
4 Correct 0 ms 348 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct!
2 Correct 0 ms 348 KB Correct!
3 Correct 1 ms 348 KB Correct!
4 Correct 0 ms 348 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Correct!
2 Correct 5 ms 536 KB Correct!
3 Correct 6 ms 348 KB Correct!
4 Correct 4 ms 348 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 71 ms 1748 KB Correct!
2 Correct 70 ms 1744 KB Correct!
3 Correct 153 ms 3276 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 358 ms 5596 KB Correct!
2 Correct 350 ms 5584 KB Correct!
3 Correct 496 ms 5612 KB Correct!
4 Correct 505 ms 5892 KB Correct!
5 Correct 500 ms 5624 KB Correct!