Submission #846090

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

void liczenie(vector<int>a,int q,vector<int>&x,vector<int>&y)
{
    if(q==-1)
    {
        return;
    }
    int jeden=0, zero=0,ifnie=0,iftak=0;
    vector<int>b;
    vector<int>c;
    for(int 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);
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {
        int w;
        cin>>w;
        a[w]=i;
    }
    ll wynik=9999999999999;
    ll wy;
    ll wynik2;
    for(int i=0;i<k;i++)
    {   
        vector<int>x(k);
        vector<int>y(k);
        liczenie(a,k-1,x,y);
        ll r=0,u=0;
        for(int 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(int j=0;j<n;j++)
        {
            int e=a[j]%2;
            a[j]/=2;
            a[j]+=(e<<(k-1));
        }
    }
    cout<<wynik<<endl;
    //cout<<wy<<endl;
    for(int i=0;i<wynik2;i++)
    {
        cout<<2;
    }
    if((1<<(k-1))&wy)
    {
        cout<<1;
    }
    cout<<2;
    for(int 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<int>, int, std::vector<int>&, std::vector<int>&)':
cheerleaders.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i=0;i<a.size();i++)
      |                 ~^~~~~~~~~
cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:51:8: warning: 'wynik2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |     ll wynik2;
      |        ^~~~~~
cheerleaders.cpp:85:18: warning: 'wy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |     if((1<<(k-1))&wy)
      |        ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2048 ms 74552 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Correct!
2 Correct 1 ms 348 KB Correct!
3 Correct 0 ms 348 KB Correct!
4 Correct 1 ms 348 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Correct!
2 Correct 4 ms 348 KB Correct!
3 Correct 4 ms 348 KB Correct!
4 Correct 5 ms 344 KB Correct!
# Verdict Execution time Memory Grader output
1 Correct 68 ms 984 KB Correct!
2 Correct 68 ms 1116 KB Correct!
3 Correct 152 ms 1736 KB Correct!
# Verdict Execution time Memory Grader output
1 Incorrect 333 ms 3028 KB Wrong number of inversions
2 Halted 0 ms 0 KB -