답안 #1098503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098503 2024-10-09T13:11:11 Z simona1230 Olympiads (BOI19_olympiads) C++17
13 / 100
17 ms 15192 KB
#include <bits/stdc++.h>

using namespace std;

int n,k,c;
int a[2048][2048];

vector<int> v[2048];
int p[32][2048];
int used[501][2048];
int forb[501][2048];
struct team
{
    int id;
    team() {}
    team(int i)
    {
        id=i;
    }

    bool operator<(const team&t)const
    {
        int sum=0;
        for(int j=1; j<=k; j++)
        {
            int curr=v[j][p[j][t.id]];
            sum+=a[curr][j];
        }
        //cout<<t.id<<" "<<id<<endl;

        int sum2=0;
        for(int j=1; j<=k; j++)
        {
            int curr=v[j][p[j][id]];
            sum2+=a[curr][j];
        }
        return sum>sum2;
    }
};

priority_queue<team> q;
int lvl[200001];
int h;
bool cmp(int i1,int i2)
{
    return a[i1][h]>a[i2][h];
}

void read()
{
    cin>>n>>k>>c;

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            cin>>a[i][j];
            v[j].push_back(i);
        }
    }

    for(int i=1; i<=k; i++)
        h=i,sort(v[i].begin(),v[i].end(),cmp);
    for(int j=1; j<=k; j++)
        v[j].push_back(0);

    for(int i=1; i<=k; i++)
        for(int j=n; j>=1; j--)
            v[i][j]=v[i][j-1];

    /*for(int i=1; i<=k; i++)
    {
        for(int j=1; j<=n; j++)
            cout<<v[i][j]<<" ";
        cout<<endl;
    }*/
}


int comb[501][501];

void prec()
{
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=i; j++)
        {
            if(i==0||j==0||i==j)comb[i][j]=1;
            else comb[i][j]=min(c,comb[i-1][j]+comb[i-1][j-1]);
            //cout<<i<<" "<<j<<" "<<comb[i][j]<<endl;
        }
    }
}

map<set<int>,int> mp;
int num=0;
void solve()
{
    num++;
    for(int i=1; i<=k; i++)
        p[i][num]=1,used[v[i][1]][num]=1;

    q.push(num);
    while(1)
    {
        int id=q.top().id;
        q.pop();

        int in=0,lf=0;
        for(int i=1; i<=n; i++)
            if(!used[i][id])
            {
                lf++;
            }

        set<int> s;
        for(int i=1; i<=k; i++)
            s.insert(v[i][p[i][id]]);
        mp[s]++;
        if(mp[s]>1)continue;

        in=s.size();

        c-=comb[lf][k-in];
        int sum=0;
        for(int d=1; d<=k; d++)
        {
            sum+=a[v[d][p[d][id]]][d];
            //cout<<v[d][p[d][id]]<<" "<<d<<endl;
        }
        //cout<<sum<<" "<<calc[id]<<endl;
        if(c<=0)
        {
            cout<<sum<<endl;
            return;
        }

        for(auto it=s.begin(); it!=s.end(); it++)
        {
            num++;
            int i=*it;

            for(int j=1; j<=n; j++)
                forb[j][num]=forb[j][id],
                used[j][num]=used[j][id],
                p[j][num]=p[j][id];
            forb[i][num]=1;

            bool pos=1;
            for(int d=1; d<=k; d++)
            {
                while(p[d][num]<=n&&forb[v[d][p[d][num]]][num])p[d][num]++;
                if(p[d][num]>n)pos=0;
                else used[v[d][p[d][num]]][num]=1;
            }

            if(lvl[id]<=3&&pos)
            {
                lvl[num]=lvl[id]+1;
                q.push(num);
            }
            else num--;
        }
    }
}

void slow()
{
    vector<int> ans;

    if(k==3)
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                for(int l=j+1; l<=n; l++)
                {
                    int sum=0;
                    for(int d=1; d<=k; d++)
                        sum+=max(a[i][d],max(a[l][d],a[j][d]));
                    ans.push_back(sum);
                }
            }
        }

    }
    else if(k==2)
    {
        for(int i=1; i<=n; i++)
        {
            for(int j=i+1; j<=n; j++)
            {
                int sum=0;
                for(int d=1; d<=k; d++)
                    sum+=max(a[i][d],a[j][d]);
                ans.push_back(sum);
            }
        }
    }
    else
    {
        for(int i=1; i<=n; i++)
        {
            int sum=0;
            for(int d=1; d<=k; d++)
                sum+=a[i][d];
            ans.push_back(sum);
        }

    }
    sort(ans.begin(),ans.end());
    cout<<ans[ans.size()-c]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read();
    if(k<=3)slow();
    else
    {
        prec();
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3032 KB Output is correct
2 Correct 6 ms 3036 KB Output is correct
3 Correct 6 ms 3180 KB Output is correct
4 Correct 3 ms 3036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1884 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 15192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 3032 KB Output is correct
2 Correct 6 ms 3036 KB Output is correct
3 Correct 6 ms 3180 KB Output is correct
4 Correct 3 ms 3036 KB Output is correct
5 Runtime error 3 ms 1884 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -